re-add age limit for notifications

This commit is contained in:
Raicuparta 2023-11-14 08:18:04 +01:00
parent 837836a58e
commit 6b8d1e4911
9 changed files with 47 additions and 34 deletions

View File

@ -1,4 +1,7 @@
import type { BaseMod } from "../mod.js";
import { getDateAgeInHours } from "../helpers/dates.js";
const MAX_UPDATE_AGE_HOURS = 24;
export type DiffItem =
| {
@ -24,20 +27,25 @@ export function getDiff(previousDatabase: BaseMod[], nextDatabase: BaseMod[]) {
(mod) => mod.uniqueName === nextDatabaseMod.uniqueName
);
if (!previousDatabaseMod) {
diff.push({
diffType: "add",
nextMod: nextDatabaseMod,
});
continue;
}
if (
getDateAgeInHours(nextDatabaseMod.latestReleaseDate) <
MAX_UPDATE_AGE_HOURS
) {
if (!previousDatabaseMod) {
diff.push({
diffType: "add",
nextMod: nextDatabaseMod,
});
continue;
}
if (previousDatabaseMod.version !== nextDatabaseMod.version) {
diff.push({
diffType: "update",
previousMod: previousDatabaseMod,
nextMod: nextDatabaseMod,
});
if (previousDatabaseMod.version !== nextDatabaseMod.version) {
diff.push({
diffType: "update",
previousMod: previousDatabaseMod,
nextMod: nextDatabaseMod,
});
}
}
if (
@ -45,11 +53,16 @@ export function getDiff(previousDatabase: BaseMod[], nextDatabase: BaseMod[]) {
previousDatabaseMod?.prerelease?.version !==
nextDatabaseMod.prerelease.version
) {
diff.push({
diffType: "update-prerelease",
previousMod: previousDatabaseMod,
nextMod: nextDatabaseMod,
});
if (
getDateAgeInHours(nextDatabaseMod.prerelease.date) <
MAX_UPDATE_AGE_HOURS
) {
diff.push({
diffType: "update-prerelease",
previousMod: previousDatabaseMod,
nextMod: nextDatabaseMod,
});
}
}
}

View File

@ -1,5 +1,5 @@
import { RELEASE_EXTENSION } from "../constants.js";
import { getAllReleases, getOctokit } from "./helpers/octokit.js";
import { getAllReleases, getOctokit } from "./octokit.js";
const MANAGER_REPO_AUTHOR = "ow-mods";
const MANAGER_REPO_NAME = "ow-mod-manager";

View File

@ -5,9 +5,9 @@ import {
getCleanedUpReleaseList,
getRepoUpdatedAt,
getAllReleases,
} from "./helpers/octokit.js";
import { filterFulfilledPromiseSettleResults } from "./helpers/promises.js";
import { getDateAgeInHours } from "./helpers/dates.js";
} from "./octokit.js";
import { filterFulfilledPromiseSettleResults } from "../helpers/promises.js";
import { getDateAgeInHours } from "../helpers/dates.js";
import { getReadmeUrls } from "./readmes.js";
import { RELEASE_EXTENSION } from "../constants.js";
import { BaseMod, OutputMod } from "../mod.js";
@ -66,12 +66,11 @@ export async function fetchMods(
: {};
const repoURL = `${REPO_URL_BASE}/${modInfo.repo}`;
const repoVariations =
modInfo.repoVariations
? modInfo.repoVariations.map(
(value: string) => `${REPO_URL_BASE}/${value}`
)
: [];
const repoVariations = modInfo.repoVariations
? modInfo.repoVariations.map(
(value: string) => `${REPO_URL_BASE}/${value}`
)
: [];
if (!requiresUpdate) {
return {
@ -130,7 +129,8 @@ export async function fetchMods(
totalDownloadCount += modInfo.downloadCountOffset;
}
const firstReleaseDate = modInfo.firstReleaseDateOverride ??
const firstReleaseDate =
modInfo.firstReleaseDateOverride ??
(releases[releases.length - 1] ?? cleanLatestRelease).date;
const latestPrerelease = prereleases[0];

View File

@ -4,11 +4,11 @@ import path from "path";
import { fetchMods } from "./fetch-mods.js";
import { fetchModManager, type ModManagerOutput } from "./fetch-mod-manager.js";
import { toJsonString } from "./helpers/to-json-string.js";
import { toJsonString } from "../helpers/to-json-string.js";
import { getViewCounts } from "./analytics/get-view-counts.js";
import { getInstallCounts } from "./analytics/get-install-counts.js";
import { getSettledResult } from "./helpers/promises.js";
import { apiCallCount, rateLimitReached } from "./helpers/octokit.js";
import { getSettledResult } from "../helpers/promises.js";
import { apiCallCount, rateLimitReached } from "./octokit.js";
import { DATABASE_FILE_NAME } from "../constants.js";
import type { OutputMod } from "../mod.js";

View File

@ -3,7 +3,7 @@ import { type OctokitOptions } from "@octokit/core/dist-types/types.js";
import { retry } from "@octokit/plugin-retry";
import { throttling } from "@octokit/plugin-throttling";
import fetch from "node-fetch";
import { getLatestDate } from "./dates.js";
import { getLatestDate } from "../helpers/dates.js";
// It's useful to log the API call count,
// but replacing the fetch function seems to some times cause the "premature close" error.

View File

@ -1,5 +1,5 @@
import { RequestError } from "@octokit/request-error";
import { CreatedOctokit } from "./helpers/octokit.js";
import { CreatedOctokit } from "./octokit.js";
import fetch from "node-fetch";
import { ModInfo } from "../mod-info.js";