Skip to content

Commit

Permalink
Print url
Browse files Browse the repository at this point in the history
  • Loading branch information
ledyba committed Jan 13, 2025
1 parent b41c1cb commit f32636f
Showing 1 changed file with 32 additions and 3 deletions.
35 changes: 32 additions & 3 deletions server/src/cmd/sanity-check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,33 @@ import * as fs from 'fs/promises';

import Repo from '../repo/Repo.js';
import Shelf from '../shelf/Shelf.js';
import { Moment, formatMomentPath } from '../shelf/Moment.js';
import * as fml from '../lib/fml.js';

const repo = new Repo();
const shelf = new Shelf(repo);

async function findMoment(entityId: string): Promise<Set<Moment>> {
const set = new Set<Moment>();
for await(const moment of repo.enumurateAllMoments()) {
const content = fml.parse(moment.text);
for (const block of content.blocks) {
if (block.type === 'audio' || block.type === 'image' || block.type === 'video') {
if(!block.entity) {
continue;
}
if (block.entity === entityId) {
set.add(moment);
}
}
}
}
return set;
}

async function main() {
console.log('** Starting Sanity Check **');
console.log();
const repo = new Repo();
const shelf = new Shelf(repo);
try {
console.log('[Checking all moments...]')
for await(let entity of shelf.enumurateAllEntities()) {
Expand All @@ -16,7 +37,15 @@ async function main() {
try {
await fs.lstat(file);
} catch (err) {
console.log(`${entity.id}, ${file}`);
const moments = await findMoment(entity.id);
console.log(`Not found: ${entity.id}`);
for (const moment of moments) {
if (moment.timestamp === undefined) {
continue;
}
const path = formatMomentPath(moment.timestamp);
console.log(` - https://ura.hexe.net${path}`);
}
}
}
}
Expand Down

0 comments on commit f32636f

Please sign in to comment.