fix: correct Memos links and author identities
This commit is contained in:
@@ -180,6 +180,11 @@ db.exec("CREATE INDEX IF NOT EXISTS posts_source_visibility_idx ON posts(source_
|
||||
db.prepare("INSERT OR IGNORE INTO schema_migrations(version) VALUES(40)").run();
|
||||
db.exec("CREATE INDEX IF NOT EXISTS alert_deliveries_status_idx ON alert_deliveries(status,run_after)");
|
||||
db.prepare("INSERT OR IGNORE INTO schema_migrations(version) VALUES(41)").run();
|
||||
const hasMemoUrlMigration = db.prepare("SELECT 1 FROM schema_migrations WHERE version=42").get();
|
||||
if (!hasMemoUrlMigration) {
|
||||
db.exec(`UPDATE posts SET remote_url=(SELECT rtrim(s.base_url,'/') FROM sources s WHERE s.id=posts.source_id) || CASE WHEN substr(remote_memo_name,7)<>'' AND substr(remote_memo_name,7) NOT GLOB '*[^0-9]*' THEN '/m/' || substr(remote_memo_name,7) ELSE '/' || remote_memo_name END WHERE origin='memos' AND remote_memo_name LIKE 'memos/%' AND source_id IS NOT NULL`);
|
||||
db.prepare("INSERT INTO schema_migrations(version) VALUES(42)").run();
|
||||
}
|
||||
|
||||
const admin = process.env.ADMIN_USERNAME;
|
||||
const adminPassword = process.env.ADMIN_PASSWORD;
|
||||
|
||||
+5
-4
@@ -2,15 +2,16 @@ export type AuthorDisplay = {
|
||||
origin: string;
|
||||
username: string;
|
||||
name: string | null;
|
||||
remote_user?: string | null;
|
||||
remote_display_name?: string | null;
|
||||
source_base_url: string | null;
|
||||
};
|
||||
|
||||
export function postAuthorLabel(post: AuthorDisplay) {
|
||||
const linkedMemos = post.origin === "memos" || post.origin === "hub";
|
||||
const author = linkedMemos ? (post.remote_display_name || post.name || post.username) : (post.name || post.username);
|
||||
if (linkedMemos && post.source_base_url) {
|
||||
const remoteUser = post.remote_user?.split("/").filter(Boolean).at(-1);
|
||||
const author = remoteUser || (post.origin === "rss" ? post.name : post.username) || post.name || "unknown";
|
||||
if (post.source_base_url) {
|
||||
try { return `@${author}@${new URL(post.source_base_url).hostname}`; } catch { /* Keep a readable fallback for legacy malformed URLs. */ }
|
||||
}
|
||||
return `@${author}${post.name ? ` · ${post.name}` : ""}`;
|
||||
return `@${author}`;
|
||||
}
|
||||
|
||||
+6
-1
@@ -22,7 +22,12 @@ export async function getMemosIdentity(baseUrl: string, token: string) {
|
||||
if (!user.name) throw new Error("Memos did not return an account identity");
|
||||
return user;
|
||||
}
|
||||
export function memoUrl(baseUrl: string, memoName: string) { const id = memoName.split("/").at(-1); return id ? `${baseUrl.replace(/\/$/, "")}/m/${encodeURIComponent(id)}` : null; }
|
||||
export function memoUrl(baseUrl: string, memoName: string) {
|
||||
const id = memoName.split("/").at(-1);
|
||||
if (!id) return null;
|
||||
const path = /^\d+$/.test(id) ? `m/${encodeURIComponent(id)}` : `memos/${encodeURIComponent(id)}`;
|
||||
return `${baseUrl.replace(/\/$/, "")}/${path}`;
|
||||
}
|
||||
export type MemosPage = { memos: MemosMemo[]; nextPageToken: string };
|
||||
export async function listMemos(baseUrl: string, token: string, rules: MemosSyncRules = {}, page: { pageToken?: string; pageSize?: number } = {}): Promise<MemosPage> {
|
||||
let pageToken = page.pageToken || "";
|
||||
|
||||
Reference in New Issue
Block a user