v0.10.35: 原站新增内容增量导入(import-live-posts REST 19 篇 + download-missing-media 16 图)+ 博客 HTML 文章统一 single 模板布局(PostHero 白摘要/Post Views,弃旧自定义卡片版式)
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
/**
|
||||
* # 脚本 下载缺失媒体文件(media 表行存在但 public/uploads 无物理文件的)
|
||||
* 配合 import-live-posts.ts:dump 快照之后新上传的图片需从原站拉取。
|
||||
* 用法:bun scripts/download-missing-media.ts
|
||||
*/
|
||||
import { SQL } from "bun";
|
||||
import { existsSync, mkdirSync } from "node:fs";
|
||||
import { dirname, join } from "node:path";
|
||||
|
||||
const LIVE = "https://www.dusuniot.com";
|
||||
const sql = new SQL(process.env.DATABASE_URL || "postgres://dusuniot:dusuniot@127.0.0.1:25432/dusuniot", { max: 1 });
|
||||
const rows = await sql`select id, path, url from media order by id`;
|
||||
let ok = 0, fail = 0;
|
||||
for (const r of rows) {
|
||||
const f = join("public", "uploads", r.path);
|
||||
if (existsSync(f)) continue;
|
||||
const res = await fetch(`${LIVE}/wp-content/uploads/${r.path}`, { headers: { "User-Agent": "Mozilla/5.0" } });
|
||||
if (!res.ok) {
|
||||
console.log("MISS", res.status, r.path);
|
||||
fail++;
|
||||
continue;
|
||||
}
|
||||
mkdirSync(dirname(f), { recursive: true });
|
||||
await Bun.write(f, res);
|
||||
ok++;
|
||||
if (ok % 20 === 0) console.log(`... ${ok} downloaded`);
|
||||
}
|
||||
console.log("下载完成:", ok, "缺失:", fail);
|
||||
await sql.end();
|
||||
Reference in New Issue
Block a user