diff --git a/bun.lockb b/bun.lockb index 7d962cb..1d52390 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index 6235b1e..1ae75ee 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ }, "type": "module", "dependencies": { + "@zip.js/zip.js": "^2.7.52", "sssg": "git+https://git.sad.ovh/sophie/sssg#47ac0b329c1617498fc8e795cbb3d7d36483ff67" } } \ No newline at end of file diff --git a/uploadNekoweb.ts b/uploadNekoweb.ts new file mode 100644 index 0000000..ff83624 --- /dev/null +++ b/uploadNekoweb.ts @@ -0,0 +1,60 @@ +import { BlobReader, BlobWriter, ZipWriter } from "@zip.js/zip.js"; +import * as fs from "fs"; +import * as path from "path"; + +const API_KEY = process.env.API_KEY as string; + +const zipFileWriter = new BlobWriter(); +const zipWriter = new ZipWriter(zipFileWriter); + +for await (const file of fs.readdirSync("dist/", { + withFileTypes: true, + recursive: true, +})) { + if (file.isDirectory()) continue; + + const fsPath = path.join(file.parentPath, file.name); + const nekowebPath = fsPath.replace("dist/", ""); + await zipWriter.add(nekowebPath, new BlobReader(await fs.openAsBlob(fsPath))); +} + +await zipWriter.close(); + +const zipFileBlob = await zipFileWriter.getData(); + +console.log(zipFileBlob); +const createReq = await fetch("https://nekoweb.org/api/files/big/create", { + method: "GET", + headers: { + Authorization: API_KEY, + }, +}); + +console.log(createReq.status); +const bigId = (await createReq.json()).id; +const form = new FormData(); +form.append("id", bigId); +form.append("file", zipFileBlob); + +const appendReq = await fetch("https://nekoweb.org/api/files/big/append", { + method: "POST", + headers: { + Authorization: API_KEY, + }, + body: form, +}); + +console.log(appendReq.status); + +const importReq = await fetch("https://nekoweb.org/api/files/import/" + bigId, { + method: "POST", + headers: { + Authorization: API_KEY, + }, +}); + +console.log(importReq.status); + +console.log( + "If all 3 statuses above are 200, uploaded to nekoweb succesfully!" +);