Skip to content

Commit

Permalink
ID生成に使われるcreatedAtの低限を設定
Browse files Browse the repository at this point in the history
  • Loading branch information
mei23 committed Dec 5, 2023
1 parent e60f858 commit ea643f4
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/remote/activitypub/kernel/announce/note.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export default async function(resolver: Resolver, actor: IRemoteUser, activity:
const activityAudience = await parseAudience(actor, activity.to, activity.cc);

await post(actor, {
createdAt: parseDateWithLimit(activity.published, 600 * 1000) || new Date(),
createdAt: parseDateWithLimit(activity.published) || new Date(),
renote,
visibility: activityAudience.visibility,
visibleUsers: activityAudience.visibleUsers,
Expand Down
5 changes: 4 additions & 1 deletion src/remote/activitypub/misc/date.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
const TIME2000 = 946684800000;

export function parseDate(input: unknown): Date | null {
if (typeof input !== 'string') return null;
const date = new Date(input);
if (date.toString() === 'Invalid Date') return null;
return date;
}

export function parseDateWithLimit(input: unknown, positiveMs: number): Date | null {
export function parseDateWithLimit(input: unknown, positiveMs = 1000 * 60 * 10, minValue = TIME2000): Date | null {
const date = parseDate(input);
if (date == null) return null;
if (date.getTime() - Date.now() > positiveMs) return null;
if (minValue > date.getTime()) return null;
return date;
}
2 changes: 1 addition & 1 deletion src/remote/activitypub/models/note.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export async function createNote(value: string | IObject, resolver?: Resolver |
}

return await post(actor, {
createdAt: parseDateWithLimit(note.published, 600 * 1000) || new Date(),
createdAt: parseDateWithLimit(note.published) || new Date(),
files,
reply,
renote: quote,
Expand Down

0 comments on commit ea643f4

Please sign in to comment.