revert: index.ts to test share embed fix
This commit is contained in:
parent
3dca9d07a9
commit
ac4ef7eace
1 changed files with 34 additions and 73 deletions
|
@ -22,11 +22,11 @@ import { Users, Notes, UserProfiles, Pages, Channels, Clips, GalleryPosts } from
|
||||||
import * as Acct from '@/misc/acct.js';
|
import * as Acct from '@/misc/acct.js';
|
||||||
import { getNoteSummary } from '@/misc/get-note-summary.js';
|
import { getNoteSummary } from '@/misc/get-note-summary.js';
|
||||||
import { queues } from '@/queue/queues.js';
|
import { queues } from '@/queue/queues.js';
|
||||||
|
import { MINUTE, DAY } from '@/const.js';
|
||||||
import { genOpenapiSpec } from '../api/openapi/gen-spec.js';
|
import { genOpenapiSpec } from '../api/openapi/gen-spec.js';
|
||||||
import { urlPreviewHandler } from './url-preview.js';
|
import { urlPreviewHandler } from './url-preview.js';
|
||||||
import { manifestHandler } from './manifest.js';
|
import { manifestHandler } from './manifest.js';
|
||||||
import packFeed from './feed.js';
|
import packFeed from './feed.js';
|
||||||
import { MINUTE, DAY } from '@/const.js';
|
|
||||||
|
|
||||||
const _filename = fileURLToPath(import.meta.url);
|
const _filename = fileURLToPath(import.meta.url);
|
||||||
const _dirname = dirname(_filename);
|
const _dirname = dirname(_filename);
|
||||||
|
@ -185,8 +185,8 @@ router.get('/twemoji-badge/(.*)', async ctx => {
|
||||||
});
|
});
|
||||||
|
|
||||||
// ServiceWorker
|
// ServiceWorker
|
||||||
router.get(`/sw.js`, async ctx => {
|
router.get('/sw.js', async ctx => {
|
||||||
await send(ctx as any, `/sw.js`, {
|
await send(ctx as any, '/sw.js', {
|
||||||
root: swAssets,
|
root: swAssets,
|
||||||
maxage: 10 * MINUTE,
|
maxage: 10 * MINUTE,
|
||||||
});
|
});
|
||||||
|
@ -232,43 +232,8 @@ const getFeed = async (acct: string) => {
|
||||||
return user && await packFeed(user);
|
return user && await packFeed(user);
|
||||||
};
|
};
|
||||||
|
|
||||||
// As the /@user[.json|.rss|.atom]/sub endpoint is complicated, we will use a regex to switch between them.
|
|
||||||
const reUser = new RegExp(`^/@(?<user>[^/]+?)(?:\.(?<feed>json|rss|atom))?(?:/(?<sub>[^/]+))?$`);
|
|
||||||
router.get(reUser, async (ctx, next) => {
|
|
||||||
const groups = reUser.exec(ctx.originalUrl)?.groups;
|
|
||||||
if (!groups) {
|
|
||||||
await next();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx.params = groups;
|
|
||||||
|
|
||||||
console.log(ctx, ctx.params)
|
|
||||||
if (groups.feed) {
|
|
||||||
if (groups.sub) {
|
|
||||||
await next();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (groups.feed) {
|
|
||||||
case 'json':
|
|
||||||
await jsonFeed(ctx, next);
|
|
||||||
break;
|
|
||||||
case 'rss':
|
|
||||||
await rssFeed(ctx, next);
|
|
||||||
break;
|
|
||||||
case 'atom':
|
|
||||||
await atomFeed(ctx, next);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
await userPage(ctx, next);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Atom
|
// Atom
|
||||||
const atomFeed: Router.Middleware = async ctx => {
|
router.get('/@:user.atom', async ctx => {
|
||||||
const feed = await getFeed(ctx.params.user);
|
const feed = await getFeed(ctx.params.user);
|
||||||
|
|
||||||
if (feed) {
|
if (feed) {
|
||||||
|
@ -277,10 +242,10 @@ const atomFeed: Router.Middleware = async ctx => {
|
||||||
} else {
|
} else {
|
||||||
ctx.status = 404;
|
ctx.status = 404;
|
||||||
}
|
}
|
||||||
};
|
});
|
||||||
|
|
||||||
// RSS
|
// RSS
|
||||||
const rssFeed: Router.Middleware = async ctx => {
|
router.get('/@:user.rss', async ctx => {
|
||||||
const feed = await getFeed(ctx.params.user);
|
const feed = await getFeed(ctx.params.user);
|
||||||
|
|
||||||
if (feed) {
|
if (feed) {
|
||||||
|
@ -289,10 +254,10 @@ const rssFeed: Router.Middleware = async ctx => {
|
||||||
} else {
|
} else {
|
||||||
ctx.status = 404;
|
ctx.status = 404;
|
||||||
}
|
}
|
||||||
};
|
});
|
||||||
|
|
||||||
// JSON
|
// JSON
|
||||||
const jsonFeed: Router.Middleware = async ctx => {
|
router.get('/@:user.json', async ctx => {
|
||||||
const feed = await getFeed(ctx.params.user);
|
const feed = await getFeed(ctx.params.user);
|
||||||
|
|
||||||
if (feed) {
|
if (feed) {
|
||||||
|
@ -301,26 +266,19 @@ const jsonFeed: Router.Middleware = async ctx => {
|
||||||
} else {
|
} else {
|
||||||
ctx.status = 404;
|
ctx.status = 404;
|
||||||
}
|
}
|
||||||
};
|
});
|
||||||
|
|
||||||
//#region SSR (for crawlers)
|
//#region SSR (for crawlers)
|
||||||
// User
|
// User
|
||||||
const userPage: Router.Middleware = async (ctx, next) => {
|
router.get(['/@:user', '/@:user/:sub'], async (ctx, next) => {
|
||||||
const userParam = ctx.params.user;
|
const { username, host } = Acct.parse(ctx.params.user);
|
||||||
const subParam = ctx.params.sub;
|
|
||||||
const { username, host } = Acct.parse(userParam);
|
|
||||||
|
|
||||||
const user = await Users.findOneBy({
|
const user = await Users.findOneBy({
|
||||||
usernameLower: username.toLowerCase(),
|
usernameLower: username.toLowerCase(),
|
||||||
host: host ?? IsNull(),
|
host: host ?? IsNull(),
|
||||||
isSuspended: false,
|
isSuspended: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (user === null) {
|
if (user != null) {
|
||||||
await next();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const profile = await UserProfiles.findOneByOrFail({ userId: user.id });
|
const profile = await UserProfiles.findOneByOrFail({ userId: user.id });
|
||||||
const meta = await fetchMeta();
|
const meta = await fetchMeta();
|
||||||
const me = profile.fields
|
const me = profile.fields
|
||||||
|
@ -329,19 +287,22 @@ const userPage: Router.Middleware = async (ctx, next) => {
|
||||||
.map(field => field.value)
|
.map(field => field.value)
|
||||||
: [];
|
: [];
|
||||||
|
|
||||||
const userDetail = {
|
await ctx.render('user', {
|
||||||
user, profile, me,
|
user, profile, me,
|
||||||
avatarUrl: await Users.getAvatarUrl(user),
|
avatarUrl: await Users.getAvatarUrl(user),
|
||||||
sub: subParam,
|
sub: ctx.params.sub,
|
||||||
instanceName: meta.name || 'Calckey',
|
instanceName: meta.name || 'Calckey',
|
||||||
icon: meta.iconUrl,
|
icon: meta.iconUrl,
|
||||||
themeColor: meta.themeColor,
|
themeColor: meta.themeColor,
|
||||||
privateMode: meta.privateMode,
|
privateMode: meta.privateMode,
|
||||||
};
|
});
|
||||||
|
|
||||||
await ctx.render('user', userDetail);
|
|
||||||
ctx.set('Cache-Control', 'public, max-age=15');
|
ctx.set('Cache-Control', 'public, max-age=15');
|
||||||
};
|
} else {
|
||||||
|
// リモートユーザーなので
|
||||||
|
// モデレータがAPI経由で参照可能にするために404にはしない
|
||||||
|
await next();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
router.get('/users/:user', async ctx => {
|
router.get('/users/:user', async ctx => {
|
||||||
const user = await Users.findOneBy({
|
const user = await Users.findOneBy({
|
||||||
|
|
Loading…
Reference in a new issue