Files
drop/server/internal/tasks/registry/update.ts
Husky 681efe95af i18n Support and Task improvements (#80)
* fix: release workflow

* feat: move mostly to internal tasks system

* feat: migrate object clean to new task system

* fix: release not  getting good base version

* chore: set version v0.3.0

* chore: style

* feat: basic task concurrency

* feat: temp pages to fill in page links

* feat: inital i18n support

* feat: localize store page

* chore: style

* fix: weblate doesn't like multifile thing

* fix: update nuxt

* feat: improved error logging

* fix: using old task api

* feat: basic translation docs

* feat: add i18n eslint plugin

* feat: translate store and auth pages

* feat: more translation progress

* feat: admin dash i18n progress

* feat: enable update check by default in prod

* fix: using wrong i18n keys

* fix: crash in library sources page

* feat: finish i18n work

* fix: missing i18n translations

* feat: use twemoji for emojis

* feat: sanatize object ids

* fix: EmojiText's alt text

* fix: UserWidget not using links

* feat: cache and auth for emoji api

* fix: add more missing translations
2025-06-05 09:53:30 +10:00

99 lines
3.0 KiB
TypeScript

import { type } from "arktype";
import * as semver from "semver";
import { defineDropTask } from "..";
import { systemConfig } from "../../config/sys-conf";
import notificationSystem from "../../notifications";
const latestRelease = type({
url: "string", // api url for specific release
html_url: "string", // user facing url
id: "number", // release id
tag_name: "string", // tag used for release
name: "string", // release name
draft: "boolean",
prerelease: "boolean",
created_at: "string",
published_at: "string",
});
export default defineDropTask({
buildId: () => `check:update:${new Date().toISOString()}`,
name: "Check for Update",
acls: [],
taskGroup: "check:update",
async run({ log }) {
// TODO: maybe implement some sort of rate limit thing to prevent this from calling github api a bunch in the event of crashloop or whatever?
// probably will require custom task scheduler for object cleanup anyway, so something to thing about
if (!systemConfig.shouldCheckForUpdates()) {
log("Update check is disabled by configuration");
return;
}
log("Checking for update");
const currVerStr = systemConfig.getDropVersion();
const currVer = semver.coerce(currVerStr);
if (currVer === null) {
const msg = "Drop provided a invalid semver tag";
log(msg);
throw new Error(msg);
}
const response = await fetch(
"https://api.github.com/repos/Drop-OSS/drop/releases/latest",
);
// if response failed somehow
if (!response.ok) {
log(
"Failed to check for update " +
JSON.stringify({
status: response.status,
body: response.body,
}),
);
throw new Error(
`Failed to check for update: ${response.status} ${response.body}`,
);
}
// parse and validate response
const resJson = await response.json();
const body = latestRelease(resJson);
if (body instanceof type.errors) {
log(body.summary);
log("GitHub Api response" + JSON.stringify(resJson));
throw new Error(
`GitHub Api response did not match expected schema: ${body.summary}`,
);
}
// parse remote version
const latestVer = semver.coerce(body.tag_name);
if (latestVer === null) {
const msg = "Github Api returned invalid semver tag";
log(msg);
throw new Error(msg);
}
// TODO: handle prerelease identifiers https://github.com/npm/node-semver#prerelease-identifiers
// check if is newer version
if (semver.gt(latestVer, currVer)) {
log("Update available");
notificationSystem.systemPush({
nonce: `drop-update-available-${currVer}-to-${latestVer}`,
title: `Update available to v${latestVer}`,
description: `A new version of Drop is available v${latestVer}`,
actions: [`View|${body.html_url}`],
acls: ["system:notifications:read"],
});
} else {
log("no update available");
}
log("Done");
},
});