Skip to content

Commit

Permalink
Merge pull request #11 from nacika-ins/fix/rate-limit-error
Browse files Browse the repository at this point in the history
fix: Fixed a problem with incorrectly specified IDs for timeline patr…
  • Loading branch information
nacika-ins authored Feb 19, 2024
2 parents 73bd5d4 + 8c28d14 commit b70ac8b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
10 changes: 5 additions & 5 deletions features/batch/mastodon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,19 @@ export const execMastodon = async (provider: TargetProvider, spamTexts: string[]
// .add(-72, 'h') : null) ?? new Date(Date.now() - 72 * 60 * 60 * 1000));
const offsetDate = dayjs(lastChecked ?? new Date(Date.now() - 72 * 60 * 60 * 1000));

let sinceId: string | null | undefined;
let maxId: string | null | undefined;

for (const _ of Array(999).fill(null)) {

// eslint-disable-next-line no-loop-func
const statuses = await retry(async () => masto.v1.timelines.public.list({
limit: 40,
sinceId,
maxId,
}));
sinceId = statuses[statuses.length - 1]?.id as string | null | undefined;
console.debug('sinceId =', sinceId);
maxId = statuses[statuses.length - 1]?.id as string | null | undefined;
console.debug('maxId =', maxId);

if (sinceId === null || sinceId === undefined) {
if (maxId === null || maxId === undefined) {
console.debug('No more status');
break;
}
Expand Down
20 changes: 10 additions & 10 deletions features/batch/misskey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ defaultRetryConfig.logger = (log) => {
console.log('[retry]', log);
};

const getGlobalTimeline = async ({ provider, sinceId }: { provider: TargetProvider, sinceId: string | undefined | null }) =>
const getGlobalTimeline = async ({ provider, untilId }: { provider: TargetProvider, untilId: string | undefined | null }) =>
axios.post<MisskeyNotes>(`${provider.apiEndpoint}/notes/global-timeline`?.replace('//', '/'), {
i: provider.apiToken,
limit: 40,
sinceId,
untilId,
}, {
headers: {
Authorization: `Bearer ${provider.apiToken}`,
Expand All @@ -33,7 +33,7 @@ const getGlobalTimeline = async ({ provider, sinceId }: { provider: TargetProvid
return [] as MisskeyNotes;
});

const getNotifications = async ({ provider, sinceId }: { provider: TargetProvider, sinceId: string | undefined | null }) =>
const getNotifications = async ({ provider, untilId }: { provider: TargetProvider, untilId: string | undefined | null }) =>
axios.post<MisskeyNotifications>(`${provider.apiEndpoint}/i/notifications`?.replace('//', '/'), {
i: provider.apiToken,
limit: 40,
Expand All @@ -46,7 +46,7 @@ const getNotifications = async ({ provider, sinceId }: { provider: TargetProvide
excludeTypes: [
'follow',
],
sinceId,
untilId,
}, {
headers: {
Authorization: `Bearer ${provider.apiToken}`,
Expand Down Expand Up @@ -138,18 +138,18 @@ export const execMisskey = async (provider: TargetProvider, spamTexts: string[],
// .add(-72, 'h') : null) ?? new Date(Date.now() - 48 * 60 * 60 * 1000));
const offsetDate = dayjs(lastChecked ?? new Date(Date.now() - 72 * 60 * 60 * 1000));

let sinceId: string | null | undefined;
let untilId: string | null | undefined;

for (const _ of Array(999).fill(null)) {

// eslint-disable-next-line no-loop-func
const notes = await retry(() => getGlobalTimeline({ provider, sinceId }));
const notes = await retry(() => getGlobalTimeline({ provider, untilId }));

console.debug('[old] sinceId =', sinceId);
sinceId = notes[notes.length - 1]?.id as string | null | undefined;
console.debug('[new] sinceId =', sinceId);
console.debug('[old] untilId =', untilId);
untilId = notes[notes.length - 1]?.id as string | null | undefined;
console.debug('[new] untilId =', untilId);

if (sinceId === null || sinceId === undefined) {
if (untilId === null || untilId === undefined) {
console.debug('No more notes');
break;
}
Expand Down

0 comments on commit b70ac8b

Please sign in to comment.