added r2 <3
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
# Plant this in your home dir
|
||||
S3_ACCESS_KEY=xxxxxxxxxxxxxxxx
|
||||
S3_SECRET_KEY=xxxxxxxxxxxxxxxx
|
||||
S3_BUCKET_NAME=dotfiles-screenshot
|
||||
S3_ENDPOINT_URL="https://xxxxxxxxxxxxxxxx.r2.cloudflarestorage.com"
|
||||
@@ -3,6 +3,12 @@ import { Command } from "commander";
|
||||
import sharp from "sharp";
|
||||
import { writeFileSync } from "fs";
|
||||
|
||||
async function getFilename(): Promise<string> {
|
||||
const _d = new Date();
|
||||
const windowClass = await $`hyprctl activewindow -j`.json();
|
||||
return `${windowClass.initialClass || "Hyprland"}-${_d.getTime()}`;
|
||||
}
|
||||
|
||||
const program = new Command("handle-screenshot");
|
||||
|
||||
const SCREENSHOT_PATH = `/home/ocbwoy3/Pictures/Screenshots`;
|
||||
@@ -48,8 +54,7 @@ async function transformImage(b: Buffer): Promise<Buffer> {
|
||||
const _BUF = await $`grim -t png -l 0 -g ${selection.stdout.toString().trim()} -`.arrayBuffer();
|
||||
let BUF = Buffer.from(_BUF) as Buffer;
|
||||
|
||||
const _d = new Date();
|
||||
const FILENAME = `${SCREENSHOT_PATH}/${_d.toISOString()}-${_d.getTime()}.png`
|
||||
const FILENAME = `${SCREENSHOT_PATH}/${await getFilename()}.png`;
|
||||
|
||||
// BUF = await transformImage(BUF);
|
||||
writeFileSync(FILENAME,BUF);
|
||||
@@ -66,8 +71,7 @@ async function transformImage(b: Buffer): Promise<Buffer> {
|
||||
const _BUF = await $`grim -t png -l 0 -o ${selection.trim()} -`.arrayBuffer();
|
||||
let BUF = Buffer.from(_BUF) as Buffer;
|
||||
|
||||
const _d = new Date();
|
||||
const FILENAME = `${SCREENSHOT_PATH}/${_d.toISOString()}-${_d.getTime()}.png`
|
||||
const FILENAME = `${SCREENSHOT_PATH}/${await getFilename()}.png`;
|
||||
|
||||
// BUF = await transformImage(BUF);
|
||||
writeFileSync(FILENAME,BUF);
|
||||
|
||||
41
scripts/bin/r2Upload.ts
Normal file
41
scripts/bin/r2Upload.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import { $, S3Client } from "bun";
|
||||
import { configDotenv } from "dotenv";
|
||||
import { homedir } from "os";
|
||||
import { readdirSync, readFileSync, statSync } from "fs";
|
||||
import { join } from "path";
|
||||
|
||||
try {
|
||||
configDotenv({
|
||||
path: `${homedir()}/.ocbwoy3-dotfiles-SECRET-DO-NOT-TOUCH.env`
|
||||
});
|
||||
|
||||
const bucket = new S3Client({
|
||||
accessKeyId: process.env.S3_ACCESS_KEY,
|
||||
secretAccessKey: process.env.S3_SECRET_KEY,
|
||||
bucket: process.env.S3_BUCKET_NAME,
|
||||
endpoint: process.env.S3_ENDPOINT_URL,
|
||||
});
|
||||
|
||||
const screenshotsDir = join(homedir(), "Pictures", "Screenshots");
|
||||
const files = readdirSync(screenshotsDir);
|
||||
|
||||
const latestFile = files
|
||||
.map(file => ({
|
||||
file,
|
||||
time: statSync(join(screenshotsDir, file)).mtime.getTime()
|
||||
}))
|
||||
.sort((a, b) => b.time - a.time)[0].file;
|
||||
|
||||
const filePath = join(screenshotsDir, latestFile);
|
||||
|
||||
const start = Date.now();
|
||||
const file = bucket.file(latestFile)
|
||||
await file.write(readFileSync(filePath), {
|
||||
type: "image/png"
|
||||
})
|
||||
$`echo "https://i.darktru.win/${latestFile}" | wl-copy -n`.nothrow().catch(a => { });
|
||||
$`notify-send "Screenshot" "Uploaded in ${Date.now() - start}ms"`.nothrow().catch(a => { });
|
||||
} catch (e_) {
|
||||
$`notify-send "Screenshot" "${`${e_}`}"`.nothrow().catch(a => { });
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/bin/bash
|
||||
|
||||
pkill -9 waybar
|
||||
trap "pkill -9 waybar" EXIT
|
||||
|
||||
hyprctl dispatch exec "GTK_THEME=Adwaita waybar -c ~/config/config/waybar/config -s ~/config/config/waybar/style.css" &
|
||||
hyprctl reload
|
||||
|
||||
Reference in New Issue
Block a user