zrcadlo https://github.com/atscan/atscan
url redirect for handles
This commit is contained in:
rodič
2828692928
revize
93fd9113f2
|
@ -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 });
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 {
|
Načítá se…
Odkázat v novém úkolu