54 lines
1.5 KiB
JavaScript
54 lines
1.5 KiB
JavaScript
import postgres from "npm:postgres";
|
|
import { parse } from "npm:smol-toml";
|
|
import { readdir, rename } from "node:fs/promises";
|
|
|
|
const config = parse(await Deno.readTextFile(Deno.cwd() + "/tetratto.toml"), {
|
|
integersAsBigInt: true,
|
|
});
|
|
|
|
const db = postgres({
|
|
user: config.database.user,
|
|
password: config.database.password,
|
|
database: config.database.name,
|
|
hostname: config.database.url.split(":")[0],
|
|
port: config.database.url.split(":")[1],
|
|
});
|
|
|
|
let i = 0;
|
|
for (const fname of await readdir(Deno.cwd() + "/media/avatars")) {
|
|
const [uid, type] = fname.split(".");
|
|
|
|
await db`INSERT INTO uploads VALUES (${BigInt(uid)}, ${BigInt(new Date().getTime())}, ${BigInt(uid)}, 'avatars', ${JSON.stringify(
|
|
{
|
|
what: type.charAt(0).toUpperCase() + type.slice(1),
|
|
},
|
|
)});`;
|
|
|
|
await rename(
|
|
Deno.cwd() + "/media/avatars/" + fname,
|
|
Deno.cwd() + "/media/uploads/avatars." + fname,
|
|
);
|
|
|
|
i += 1;
|
|
console.log(`done ${i}`);
|
|
}
|
|
|
|
for (const fname of await readdir(Deno.cwd() + "/media/banners")) {
|
|
const [uid, type] = fname.split(".");
|
|
|
|
await db`INSERT INTO uploads VALUES (${BigInt(uid)}, ${BigInt(new Date().getTime())}, ${BigInt(uid)}, 'banners', ${JSON.stringify(
|
|
{
|
|
what: type.charAt(0).toUpperCase() + type.slice(1),
|
|
},
|
|
)});`;
|
|
|
|
await rename(
|
|
Deno.cwd() + "/media/banners/" + fname,
|
|
Deno.cwd() + "/media/uploads/banners." + fname,
|
|
);
|
|
|
|
i += 1;
|
|
console.log(`done ${i}`);
|
|
}
|
|
|
|
await db.end();
|