Switched to using e-z.gg
This commit is contained in:
18
flake.lock
generated
18
flake.lock
generated
@@ -38,11 +38,11 @@
|
|||||||
"nixpkgs": "nixpkgs"
|
"nixpkgs": "nixpkgs"
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1745006048,
|
"lastModified": 1750153510,
|
||||||
"narHash": "sha256-4ONXaEwnyZGPp84d6wjiqoR4xyTWygUobBTcSkILPzU=",
|
"narHash": "sha256-NYHXXJZ9m4fJpKk9tKn/EExX87SqcBcRINOGF7hKRLI=",
|
||||||
"owner": "catppuccin",
|
"owner": "catppuccin",
|
||||||
"repo": "nix",
|
"repo": "nix",
|
||||||
"rev": "592094a02c4e43a9fa33559ade84d1ca015e8ada",
|
"rev": "4e95eaf8a351956d75cc400318579967ca2b6d0f",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
@@ -494,11 +494,11 @@
|
|||||||
"systems": "systems_3"
|
"systems": "systems_3"
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1739049114,
|
"lastModified": 1749155770,
|
||||||
"narHash": "sha256-jD9W4OHcn1sJ+xbwNFbGN9heSE6v2v3U+FtGf8Cul6k=",
|
"narHash": "sha256-gsdM6QEHSpzj1Vgw03t5INA+kSZzBWm0qxdofcBp8Qo=",
|
||||||
"owner": "hyprwm",
|
"owner": "hyprwm",
|
||||||
"repo": "hyprsysteminfo",
|
"repo": "hyprsysteminfo",
|
||||||
"rev": "6769e50fcfcfd56548e9b17b9a02641ab4826e38",
|
"rev": "3feb86f866b428ee1b78968e222cee6570a38658",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
@@ -1052,11 +1052,11 @@
|
|||||||
"nixpkgs": "nixpkgs_6"
|
"nixpkgs": "nixpkgs_6"
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1748377319,
|
"lastModified": 1750152169,
|
||||||
"narHash": "sha256-X4lsXJaGVvWnsnhPE2GdQX48BGJOyh8VIziIZT99oiM=",
|
"narHash": "sha256-XN5OBCCXKmPBL+UXyyScI5HGgs4U8OFGQTnKuxurBFI=",
|
||||||
"owner": "0xc000022070",
|
"owner": "0xc000022070",
|
||||||
"repo": "zen-browser-flake",
|
"repo": "zen-browser-flake",
|
||||||
"rev": "4d69a89a06542fcc0f4ff7d3fa45e49e7ce691f8",
|
"rev": "ed811ab0d0b407b59cda1023820e9986fd28c8c3",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
import { $, S3Client } from "bun";
|
import { $ } from "bun";
|
||||||
import { configDotenv } from "dotenv";
|
import { configDotenv } from "dotenv";
|
||||||
import { homedir } from "os";
|
import { homedir } from "os";
|
||||||
import { readdirSync, readFileSync, statSync } from "fs";
|
import { readdirSync, readFileSync, statSync } from "fs";
|
||||||
import { join } from "path";
|
import { join } from "path";
|
||||||
import { setConsoleTitle } from "@ocbwoy3/libocbwoy3";
|
import { setConsoleTitle } from "@ocbwoy3/libocbwoy3";
|
||||||
|
import { UploadToEZ } from "../lib/EZUploader";
|
||||||
|
|
||||||
setConsoleTitle("R2 Uploader");
|
setConsoleTitle("Screenshot Uploader");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const start = Date.now();
|
const start = Date.now();
|
||||||
@@ -14,15 +15,6 @@ try {
|
|||||||
path: `${homedir()}/.ocbwoy3-dotfiles-SECRET-DO-NOT-TOUCH.env`
|
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,
|
|
||||||
});
|
|
||||||
|
|
||||||
let urlParams = "";
|
|
||||||
|
|
||||||
const screenshotsDir = join(homedir(), "Pictures", "Screenshots");
|
const screenshotsDir = join(homedir(), "Pictures", "Screenshots");
|
||||||
const files = readdirSync(screenshotsDir);
|
const files = readdirSync(screenshotsDir);
|
||||||
|
|
||||||
@@ -35,29 +27,11 @@ try {
|
|||||||
|
|
||||||
const filePath = join(screenshotsDir, latestFile);
|
const filePath = join(screenshotsDir, latestFile);
|
||||||
|
|
||||||
let [ _, regretevator, floorNum ] = latestFile.match(/\-(regretevator)\-?([0-9]+)?\.png$/) || [];
|
const url = await UploadToEZ(readFileSync(filePath));
|
||||||
|
|
||||||
// the devs changed rich presence, what's the point of parsing the filename if tuxstrap doesn't update the state file anymore?
|
$`echo "${url}" | wl-copy -n`.nothrow().catch(a => { });
|
||||||
if (regretevator === "regretevator") {
|
$`notify-send "Screenshot" "Uploaded to e-z.host in ${Date.now() - start}ms, URL copied to clipboard"`.nothrow().catch(a => { });
|
||||||
latestFile = latestFile.replace(`-regretevator${floorNum ? `-${floorNum}` : ""}.png`,".png")
|
|
||||||
// OR i could keep the filename and have my worker parse the filename
|
|
||||||
if (floorNum) {
|
|
||||||
urlParams = `?floor=${floorNum}`
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const file = bucket.file(latestFile)
|
|
||||||
await file.write(readFileSync(filePath), {
|
|
||||||
type: "image/png"
|
|
||||||
})
|
|
||||||
$`echo "https://i.darktru.win/${encodeURIComponent(latestFile)}${urlParams}" | wl-copy -n`.nothrow().catch(a => { });
|
|
||||||
$`notify-send "Screenshot" "Uploaded in ${Date.now() - start}ms<br/><small>${latestFile}</small>"`.nothrow().catch(a => { });
|
|
||||||
} catch (e_) {
|
} catch (e_) {
|
||||||
const cx = `${e_}`.toLowerCase();
|
|
||||||
if (cx.includes("enable r2") && cx.includes("cloudflare dashboard")) {
|
|
||||||
$`notify-send "Screenshot" "YOU OWE CLOUDFLARE MONEY!!!!"`.nothrow().catch(a => { });
|
|
||||||
process.exit(0);
|
|
||||||
}
|
|
||||||
$`notify-send "Screenshot" "${`${e_}`}"`.nothrow().catch(a => { });
|
$`notify-send "Screenshot" "${`${e_}`}"`.nothrow().catch(a => { });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
49
scripts/lib/EZUploader.ts
Normal file
49
scripts/lib/EZUploader.ts
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
import { homedir } from "os";
|
||||||
|
const API_URL = "https://api.e-z.host/files";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Uploads a PNG image to e-z and returns the embed URL.
|
||||||
|
* Throws an error if the file is not a PNG.
|
||||||
|
*
|
||||||
|
* @param content Image content as a Buffer
|
||||||
|
* @returns The uploaded image's URL
|
||||||
|
*/
|
||||||
|
export async function UploadToEZ(content: Buffer): Promise<string> {
|
||||||
|
if (!process.env.EZ_API_KEY) {
|
||||||
|
throw new Error(`Missing \`EZ_API_KEY\`, make sure you're loading the env from \`${homedir()}/.ocbwoy3-dotfiles-SECRET-DO-NOT-TOUCH.env\`!`)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(content[0] === 0x89 && content[1] === 0x50 && content[2] === 0x4e)) {
|
||||||
|
throw new Error("File is not a PNG.");
|
||||||
|
}
|
||||||
|
|
||||||
|
const form = new FormData();
|
||||||
|
form.append(
|
||||||
|
"file",
|
||||||
|
new Blob([content], { type: "image/png" }),
|
||||||
|
"screenshot.png"
|
||||||
|
);
|
||||||
|
|
||||||
|
const res = await fetch(API_URL, {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
key: process.env.EZ_API_KEY,
|
||||||
|
},
|
||||||
|
body: form,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!res.ok) {
|
||||||
|
throw new Error(
|
||||||
|
`Upload failed with status ${res.status}: ${await res.text()}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const json = await res.json();
|
||||||
|
|
||||||
|
if (!json.imageUrl) {
|
||||||
|
console.warn(json);
|
||||||
|
throw new Error("Malformed response from e-z.gg");
|
||||||
|
}
|
||||||
|
|
||||||
|
return json.url;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user