This commit is contained in:
parent
b31eca5afa
commit
0d7cae9b8f
|
@ -13,6 +13,7 @@
|
|||
},
|
||||
"type": "module",
|
||||
"dependencies": {
|
||||
"@zip.js/zip.js": "^2.7.52",
|
||||
"sssg": "git+https://git.sad.ovh/sophie/sssg#47ac0b329c1617498fc8e795cbb3d7d36483ff67"
|
||||
}
|
||||
}
|
60
uploadNekoweb.ts
Normal file
60
uploadNekoweb.ts
Normal file
|
@ -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!"
|
||||
);
|
Loading…
Reference in a new issue