0
0
This commit is contained in:
syuilo 2022-03-01 01:24:50 +09:00
parent 8dcdbddbfb
commit 4701127946
5 changed files with 13 additions and 13 deletions

View File

@ -57,15 +57,15 @@ function validateActor(x: IObject, uri: string): IActor {
if (e) throw new Error(`invalid Actor: ${name} ${e.message}`); if (e) throw new Error(`invalid Actor: ${name} ${e.message}`);
}; };
validate('id', x.id, $.str.min(1)); validate('id', x.id, $.default.str.min(1));
validate('inbox', x.inbox, $.str.min(1)); validate('inbox', x.inbox, $.default.str.min(1));
validate('preferredUsername', x.preferredUsername, $.str.min(1).max(128).match(/^\w([\w-.]*\w)?$/)); validate('preferredUsername', x.preferredUsername, $.default.str.min(1).max(128).match(/^\w([\w-.]*\w)?$/));
// These fields are only informational, and some AP software allows these // These fields are only informational, and some AP software allows these
// fields to be very long. If they are too long, we cut them off. This way // fields to be very long. If they are too long, we cut them off. This way
// we can at least see these users and their activities. // we can at least see these users and their activities.
validate('name', truncate(x.name, nameLength), $.optional.nullable.str); validate('name', truncate(x.name, nameLength), $.default.optional.nullable.str);
validate('summary', truncate(x.summary, summaryLength), $.optional.nullable.str); validate('summary', truncate(x.summary, summaryLength), $.default.optional.nullable.str);
const idHost = toPuny(new URL(x.id!).hostname); const idHost = toPuny(new URL(x.id!).hostname);
if (idHost !== expectHost) { if (idHost !== expectHost) {

View File

@ -26,7 +26,7 @@ export async function resolveUser(username: string, host: string | null, option?
host = toPuny(host); host = toPuny(host);
if (config.host == host) { if (config.host === host) {
logger.info(`return local user: ${usernameLower}`); logger.info(`return local user: ${usernameLower}`);
return await Users.findOne({ usernameLower, host: null }).then(u => { return await Users.findOne({ usernameLower, host: null }).then(u => {
if (u == null) { if (u == null) {

View File

@ -15,10 +15,10 @@ export default async (ctx: Router.RouterContext) => {
const userId = ctx.params.user; const userId = ctx.params.user;
// Get 'cursor' parameter // Get 'cursor' parameter
const [cursor, cursorErr] = $.optional.type(ID).get(ctx.request.query.cursor); const [cursor, cursorErr] = $.default.optional.type(ID).get(ctx.request.query.cursor);
// Get 'page' parameter // Get 'page' parameter
const pageErr = !$.optional.str.or(['true', 'false']).ok(ctx.request.query.page); const pageErr = !$.default.optional.str.or(['true', 'false']).ok(ctx.request.query.page);
const page: boolean = ctx.request.query.page === 'true'; const page: boolean = ctx.request.query.page === 'true';
// Validate parameters // Validate parameters

View File

@ -16,10 +16,10 @@ export default async (ctx: Router.RouterContext) => {
const userId = ctx.params.user; const userId = ctx.params.user;
// Get 'cursor' parameter // Get 'cursor' parameter
const [cursor, cursorErr] = $.optional.type(ID).get(ctx.request.query.cursor); const [cursor, cursorErr] = $.default.optional.type(ID).get(ctx.request.query.cursor);
// Get 'page' parameter // Get 'page' parameter
const pageErr = !$.optional.str.or(['true', 'false']).ok(ctx.request.query.page); const pageErr = !$.default.optional.str.or(['true', 'false']).ok(ctx.request.query.page);
const page: boolean = ctx.request.query.page === 'true'; const page: boolean = ctx.request.query.page === 'true';
// Validate parameters // Validate parameters

View File

@ -20,13 +20,13 @@ export default async (ctx: Router.RouterContext) => {
const userId = ctx.params.user; const userId = ctx.params.user;
// Get 'sinceId' parameter // Get 'sinceId' parameter
const [sinceId, sinceIdErr] = $.optional.type(ID).get(ctx.request.query.since_id); const [sinceId, sinceIdErr] = $.default.optional.type(ID).get(ctx.request.query.since_id);
// Get 'untilId' parameter // Get 'untilId' parameter
const [untilId, untilIdErr] = $.optional.type(ID).get(ctx.request.query.until_id); const [untilId, untilIdErr] = $.default.optional.type(ID).get(ctx.request.query.until_id);
// Get 'page' parameter // Get 'page' parameter
const pageErr = !$.optional.str.or(['true', 'false']).ok(ctx.request.query.page); const pageErr = !$.default.optional.str.or(['true', 'false']).ok(ctx.request.query.page);
const page: boolean = ctx.request.query.page === 'true'; const page: boolean = ctx.request.query.page === 'true';
// Validate parameters // Validate parameters