url redirect for handles

This commit is contained in:
tree 2023-07-07 17:23:53 +00:00
rodič 2828692928
revize 93fd9113f2
5 změnil soubory, kde provedl 18 přidání a 6 odebrání

Zobrazit soubor

@ -353,7 +353,15 @@ router
})
.get("/:id", async (ctx) => {
if (!ctx.params.id.match(/^did\:/)) {
return ctx.status = 404;
// try to lookup for handle
const handle = await ats.db.did.findOne({
"revs.operation.alsoKnownAs": `at://${ctx.params.id}`,
});
if (handle) {
return ctx.response.redirect(`/${handle.did}`);
} else {
return ctx.status = 404;
}
}
const did = ctx.params.id;
const item = await ats.db.did.findOne({ did });

Zobrazit soubor

@ -3,7 +3,7 @@ import { timeout } from "./utils.js";
import { join } from "https://deno.land/std@0.192.0/path/posix.ts";
import { ensureDir } from "https://deno.land/std@0.192.0/fs/ensure_dir.ts";
import * as fsize from "npm:filesize";
import * as zstd from 'https://deno.land/x/zstd_wasm/deno/zstd.ts';
import * as zstd from "https://deno.land/x/zstd_wasm/deno/zstd.ts";
import { Sha256 } from "https://deno.land/std@0.119.0/hash/sha256.ts";
const filesize = fsize.filesize;
@ -108,7 +108,9 @@ export async function saveRepo(ats, didInfo, job = null) {
await job.log(
`[${did}@${pds}] displayName=${
JSON.stringify(repo.profile?.displayName)
} [${filesize(repo.size)}] compressed: ${carFnCompressed} [${filesize(repo.sizeCompressed)}]`,
} [${filesize(repo.size)}] compressed: ${carFnCompressed} [${
filesize(repo.sizeCompressed)
}]`,
);
await job.updateProgress(99);
}

Zobrazit soubor

@ -2,7 +2,6 @@
import { config } from '$lib/config';
export async function request(fetch, path, ...args) {
console.log(path);
const res = await fetch(config.api + path, ...args);
if (!res || res.status !== 200) {
return null;

Zobrazit soubor

@ -1,13 +1,16 @@
import { error } from '@sveltejs/kit';
import { error, redirect } from '@sveltejs/kit';
import { request } from '$lib/api';
export async function load({ params, fetch, parent }) {
const { config } = await parent();
const did = `did:${params.id}`;
const did = params.id;
const item = await request(fetch, `/${did}`);
if (!item) {
throw error(404, { message: 'Not found' });
}
if (item.did !== did) {
throw redirect(302, `/${item.did}`);
}
const pdsHost = item.pds[0]?.replace(/^https?:\/\//, '');
const pdsRes = pdsHost ? await fetch(`${config.api}/pds/${pdsHost}`) : null;
return {