60 lines
1.4 KiB
TypeScript
60 lines
1.4 KiB
TypeScript
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!"
|
|
);
|