2024-07-30 23:24:17 +08:00
|
|
|
import { walk } from "@std/fs/walk";
|
|
|
|
import { resolve } from "@std/path";
|
2024-03-16 22:29:24 +08:00
|
|
|
import { mime } from "mimetypes";
|
2024-02-29 22:23:05 +08:00
|
|
|
import { FileMeta } from "../plug-api/types.ts";
|
2022-10-29 22:27:16 +08:00
|
|
|
|
2023-07-06 22:47:50 +08:00
|
|
|
const rootDir = resolve("website_build");
|
2023-05-24 02:53:53 +08:00
|
|
|
|
|
|
|
const lastModifiedTimestamp = +Deno.env.get("LAST_MODIFIED_TIMESTAMP")! ||
|
|
|
|
Date.now();
|
2022-10-29 22:27:16 +08:00
|
|
|
|
|
|
|
const allFiles: FileMeta[] = [];
|
|
|
|
for await (
|
|
|
|
const file of walk(rootDir, {
|
|
|
|
includeDirs: false,
|
|
|
|
// Exclude hidden files
|
2023-08-01 03:06:08 +08:00
|
|
|
skip: [
|
|
|
|
/^.*\/(\..+|_redirects|_headers|service_worker\.js.*|index\.json|_client\/.*)$/,
|
|
|
|
],
|
2022-10-29 22:27:16 +08:00
|
|
|
})
|
|
|
|
) {
|
|
|
|
const fullPath = file.path;
|
|
|
|
const s = await Deno.stat(fullPath);
|
|
|
|
allFiles.push({
|
|
|
|
name: fullPath.substring(rootDir.length + 1),
|
2023-05-24 02:53:53 +08:00
|
|
|
lastModified: lastModifiedTimestamp,
|
2023-11-03 16:38:04 +08:00
|
|
|
created: lastModifiedTimestamp,
|
2022-10-29 22:27:16 +08:00
|
|
|
contentType: mime.getType(fullPath) || "application/octet-stream",
|
|
|
|
size: s.size,
|
|
|
|
perm: "rw",
|
|
|
|
});
|
|
|
|
}
|
|
|
|
console.log(JSON.stringify(allFiles, null, 2));
|