nycki.net/tools/publish-neocities.js

28 lines
783 B
JavaScript
Raw Permalink Normal View History

2024-12-28 06:46:03 +00:00
import fs from 'node:fs/promises';
import path from 'node:path';
import dotenv from 'dotenv';
import Neocities from 'neocities'
const uploadDir = 'tools/neocities';
async function listFiles() {
const files = [];
for (let name of await fs.readdir(uploadDir, { recursive: true })) {
const file = path.join(uploadDir, name);
const stat = await fs.stat(file);
if (stat.isDirectory()) continue;
files.push({ name: name, path: file });
}
return files;
}
async function main() {
dotenv.config();
const api = new Neocities(process.env.NEOCITIES_USERNAME, process.env.NEOCITIES_PASSWORD);
const files = await listFiles();
const response = await new Promise(cb => api.upload(files, cb));
console.log(response);
}
main();