31 Commits

Author SHA1 Message Date
ace2c3c180 update dependencies 2025-08-18 14:25:38 -05:00
3019f9132f omit dev 2025-06-17 15:51:28 -05:00
a04ffade6f install python 2025-06-17 15:46:54 -05:00
a243892fd4 bump dependencies 2025-06-17 15:38:46 -05:00
1db899b5c8 4.1.2: dependencies 2025-05-04 12:55:07 -05:00
fc71bc08db Merge pull request #2 from CorySanin/dependabot/npm_and_yarn/tar-fs-2.1.2
Bump tar-fs from 2.1.1 to 2.1.2
2025-05-04 12:46:38 -05:00
dependabot[bot]
c560100a8b Bump tar-fs from 2.1.1 to 2.1.2
Bumps [tar-fs](https://github.com/mafintosh/tar-fs) from 2.1.1 to 2.1.2.
- [Commits](https://github.com/mafintosh/tar-fs/compare/v2.1.1...v2.1.2)

---
updated-dependencies:
- dependency-name: tar-fs
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-03-28 23:57:01 +00:00
3c34a98e67 4.1.1: use build script package 2025-03-18 21:28:13 -05:00
cb28872652 Merge pull request #1 from CorySanin/ts-modules
TS + modules
2025-01-28 17:54:53 -05:00
a8c057245a github action 2025-01-27 23:22:17 -05:00
d328414186 ts + modules 2025-01-27 20:11:53 -05:00
5b44841cbf 4.0.8: fun with curl 2025-01-07 01:28:35 -05:00
d07f02f4a2 4.0.7: bump dependencies, minor changes 2025-01-05 22:11:59 -05:00
fb44cf636f 4.0.6: shut down irc bot if health check is unhealthy 2024-10-30 13:33:37 -05:00
768b69ce08 4.0.5: update dependencies 2024-09-20 20:02:36 -05:00
0a63914127 Apply name compliance to artix-checkupdates output 2024-08-12 21:23:30 -05:00
568e9d186e Add package count, bump dependencies 2024-07-24 00:58:07 -05:00
fb4b291c81 only allocate for required objects 2024-07-23 00:46:47 -05:00
56c38bdefd 4.0.2: remove delay, sort maintainers' packages 2024-07-19 00:40:22 -05:00
228c462782 minor bugfixes
set up private api correctly and only send irc messages if enabled in config
2024-07-17 11:40:34 -05:00
ad14eff70b set WAL pragma 2024-07-17 00:23:45 -05:00
25e7b4b211 v4.0.0: break out components 2024-07-17 00:13:07 -05:00
65663c02dd always update base image 2024-06-18 20:37:03 -05:00
c4935a0129 update deps, add cache control to maintainers API 2024-06-18 20:30:10 -05:00
1030873894 3.4.2: bump dependencies, add package api 2024-05-12 21:48:48 -05:00
8ca4e2105d v3.4.1: Fixed link on orphan page 2024-03-24 14:18:39 -05:00
f3b63d5cbd v3.4.0: list orphan packages
track and list orphan packages

respond to requests while syncing packages

fix crashes due to configuration

bump dependency versions
2024-03-23 04:09:38 -05:00
1f54eae84d 3.3.3: automatically clear lockfiles 2024-02-29 19:18:51 -05:00
ee29453824 update base docker image tag name 2024-02-19 04:32:22 -05:00
9ffcd0b5ee fix userbar base 2024-02-16 04:28:16 -05:00
7410c7ca0c v3.3.2: dynamically generated, old-school userbar
I can't believe I'm doing this. Closes #3
2024-02-16 04:21:31 -05:00
32 changed files with 3782 additions and 1486 deletions

View File

@@ -1,3 +1,4 @@
volume/
config/
distribution/
node_modules

90
.github/workflows/build-app-image.yml vendored Normal file
View File

@@ -0,0 +1,90 @@
name: App Image CI
on:
push:
branches:
- master
tags:
- 'v*'
pull_request:
branches:
- master
jobs:
build_app_image:
name: Build app image
runs-on: ubuntu-latest
env:
GH_REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
REPOSITORY: ${{ github.event.repository.name }}
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3
with:
install: true
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.GH_REGISTRY }}
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata for release Docker image
if: startsWith(github.ref, 'refs/tags/v')
id: meta
uses: docker/metadata-action@v5
with:
images: |
${{ env.GH_REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=latest
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
- name: Extract metadata for develop Docker image
if: "!startsWith(github.ref, 'refs/tags/v')"
id: meta-develop
uses: docker/metadata-action@v5
with:
images: |
${{ env.GH_REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=ref,event=pr
- name: Build and push release Docker image
if: startsWith(github.ref, 'refs/tags/v')
uses: docker/build-push-action@v6
with:
target: deploy
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64
cache-from: type=gha,scope=${{ github.workflow }}
cache-to: type=gha,mode=max,scope=${{ github.workflow }}
- name: Build and push develop Docker image
if: "!startsWith(github.ref, 'refs/tags/v')"
uses: docker/build-push-action@v6
with:
target: deploy
push: true
tags: ${{ steps.meta-develop.outputs.tags }}
labels: ${{ steps.meta-develop.outputs.labels }}
platforms: linux/amd64
cache-from: type=gha,scope=${{ github.workflow }}
cache-to: type=gha,mode=max,scope=${{ github.workflow }}

3
.gitignore vendored
View File

@@ -108,4 +108,5 @@ docker-cache/
assets/css/
assets/js/
assets/webp/
config/
config/
distribution/

View File

@@ -1,23 +0,0 @@
image: docker:latest
services:
- docker:dind
variables:
DOCKER_DRIVER: overlay
stages:
- build
- deploy
artix-packy-pusher:
stage: build
script:
- docker build --pull --no-cache -t "$CI_REGISTRY_IMAGE" .
deploy:
stage: deploy
only:
- master
script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- docker push "$CI_REGISTRY_IMAGE"

View File

@@ -1,8 +1,12 @@
FROM artixlinux/artixlinux:devel as build-env
FROM artixlinux/artixlinux:base-devel AS baseimg
RUN pacman -Syu --noconfirm
FROM baseimg AS build-env
WORKDIR /usr/notifier
RUN pacman -Sy --noconfirm nodejs npm
RUN pacman -Sy --noconfirm nodejs npm typescript python
COPY package*.json ./
@@ -10,16 +14,17 @@ RUN npm install
COPY . .
RUN npm run-script build && \
npm ci --only=production
RUN tsc && \
npm run-script build && \
npm ci --omit=dev
FROM artixlinux/artixlinux:devel as deploy
FROM baseimg AS deploy
VOLUME /usr/notifier/config
WORKDIR /usr/notifier
HEALTHCHECK --timeout=15m \
CMD curl --fail http://localhost:8080/healthcheck || exit 1
CMD curl --fail http://localhost:8081/healthcheck || exit 1
EXPOSE 8080
@@ -38,10 +43,9 @@ RUN mkdir -p ./config /home/artix/.config/artix-checkupdates \
USER artix
ENV ARTIX_MIRROR="https://mirrors.qontinuum.space/artixlinux/%s/os/x86_64"
ENV ARCH_MIRROR="https://mirrors.qontinuum.space/archlinux/%s/os/x86_64"
ENV ARTIX_MIRROR="https://mirror.sanin.dev/artix-linux/%s/os/x86_64/"
ENV ARCH_MIRROR="https://mirror.sanin.dev/arch-linux/%s/os/x86_64/"
ENV ARTIX_REPOS="system-goblins,world-goblins,galaxy-goblins,lib32-goblins,system-gremlins,world-gremlins,galaxy-gremlins,lib32-gremlins,system,world,galaxy,lib32"
ENV ARCH_REPOS="core-staging,extra-staging,multilib-staging,core-testing,extra-testing,multilib-testing,core,extra,multilib"
ENV GITEA_TOKEN="CHANGEME"
CMD [ "node", "index.js"]
CMD [ "node", "distribution/index.mjs"]

View File

@@ -1,4 +1,4 @@
# artix-packy-notifier
# artix-checkupdates-web
Notification system and web frontend for Artix packages with pending operations. Notifications can be sent via
[Apprise](https://github.com/caronc/apprise/wiki#notification-services) or IRC. Web interface shows all packages with pending operations
@@ -33,12 +33,13 @@ If the channel is intended only for the bot to broadcast, consider setting the c
```
npm install
node index.js
npm exec tsc
node distribution/index.mjs
```
## Docker Setup
Image : `registry.gitlab.com/sanin.dev/artix-packy-notifier`
Image : `ghcr.io/corysanin/artix-checkupdates-web:latest`
mount a folder to `/usr/notifier/config`.

View File

@@ -1,31 +1,29 @@
/**
* Writing this myself because gulp has a billion garbage dependencies
* and webpack sucks poop through a straw. Everyone is stupid.
*/
const fsp = require('fs').promises;
const path = require('path');
const spawn = require('child_process').spawn;
const sass = require('sass');
const csso = require('csso');
const uglifyjs = require("uglify-js");
import fs from 'fs';
import path from 'path';
import child_process from 'child_process';
import uglifyjs from "uglify-js";
import * as sass from 'sass';
import * as csso from 'csso';
const spawn = child_process.spawn;
const fsp = fs.promises;
const STYLESDIR = 'styles';
const SCRIPTSDIR = 'scripts';
const IMAGESDIR = path.join('assets', 'images');
const STYLEOUTDIR = process.env.STYLEOUTDIR || path.join(__dirname, 'assets', 'css');
const SCRIPTSOUTDIR = process.env.SCRIPTSOUTDIR || path.join(__dirname, 'assets', 'js');
const IMAGESOUTDIR = process.env.IMAGESOUTDIR || path.join(__dirname, 'assets', 'webp');
const STYLEOUTDIR = process.env.STYLEOUTDIR || path.join('assets', 'css');
const SCRIPTSOUTDIR = process.env.SCRIPTSOUTDIR || path.join('assets', 'js');
const IMAGESOUTDIR = process.env.IMAGESOUTDIR || path.join('assets', 'webp');
const STYLEOUTFILE = process.env.STYLEOUTFILE || 'styles.css';
const SQUASH = new RegExp('^[0-9]+-');
async function emptyDir(dir) {
async function emptyDir(dir: string) {
await Promise.all((await fsp.readdir(dir, { withFileTypes: true })).map(f => path.join(dir, f.name)).map(p => fsp.rm(p, {
recursive: true,
force: true
})));
}
async function mkdir(dir) {
async function mkdir(dir: string | string[]) {
if (typeof dir === 'string') {
await fsp.mkdir(dir, { recursive: true });
}
@@ -37,8 +35,8 @@ async function mkdir(dir) {
// Process styles
async function styles() {
await mkdir([STYLEOUTDIR, STYLESDIR]);
await await emptyDir(STYLEOUTDIR);
let styles = [];
await emptyDir(STYLEOUTDIR);
let styles: string[] = [];
let files = await fsp.readdir(STYLESDIR);
await Promise.all(files.map(f => new Promise(async (res, reject) => {
let p = path.join(STYLESDIR, f);
@@ -110,7 +108,7 @@ async function images(dir = '') {
clearTimeout(timeout);
if (code === 0) {
console.log(`Wrote ${outfile}`);
res();
res(null);
}
else {
reject(code);
@@ -124,6 +122,10 @@ async function images(dir = '') {
}
}
function isAbortError(err: unknown): boolean {
return typeof err === 'object' && err !== null && 'name' in err && err.name === 'AbortError';
}
(async function () {
await Promise.all([styles(), scripts(), images()]);
if (process.argv.indexOf('--watch') >= 0) {
@@ -134,7 +136,7 @@ async function images(dir = '') {
for await (const _ of watcher)
await styles();
} catch (err) {
if (err.name === 'AbortError')
if (isAbortError(err))
return;
throw err;
}
@@ -146,7 +148,7 @@ async function images(dir = '') {
for await (const _ of watcher)
await scripts();
} catch (err) {
if (err.name === 'AbortError')
if (isAbortError(err))
return;
throw err;
}
@@ -160,7 +162,7 @@ async function images(dir = '') {
for await (const _ of watcher)
await images();
} catch (err) {
if (err.name === 'AbortError')
if (isAbortError(err))
return;
throw err;
}

View File

@@ -1,7 +1,31 @@
version: '2'
services:
packy:
artix-notifier-daemon:
container_name: artix-notifier-daemon
build:
context: ./
volumes:
- ./config:/usr/notifier/config
depends_on:
- artix-notifier-irc
- artix-notifier-web
environment:
COMPONENT: "daemon"
ARTIX_REPOS: "system-goblins,world-goblins,system-gremlins,world-gremlins,system,world"
ARCH_REPOS: "core-staging,extra-staging,core-testing,extra-testing,core,extra"
artix-notifier-irc:
container_name: artix-notifier-irc
build:
context: ./
volumes:
- ./config:/usr/notifier/config
environment:
COMPONENT: "ircbot"
artix-notifier-web:
container_name: artix-notifier-web
build:
context: ./
volumes:
@@ -9,7 +33,4 @@ services:
ports:
- 8080:8080
environment:
ARTIX_MIRROR: "https://mirrors.qontinuum.space/artixlinux/%s/os/x86_64"
ARCH_MIRROR: "https://mirrors.qontinuum.space/archlinux/%s/os/x86_64"
ARTIX_REPOS: "system-goblins,world-goblins,system-gremlins,world-gremlins,system,world"
ARCH_REPOS: "core-staging,extra-staging,core-testing,extra-testing,core,extra"
COMPONENT: "web"

249
index.js
View File

@@ -1,249 +0,0 @@
const path = require('path');
const fs = require('fs');
const spawn = require('child_process').spawn;
const cron = require('node-cron');
const dayjs = require('dayjs');
const json5 = require('json5');
const phin = require('phin');
const DB = require('./db');
const IRCBot = require('./ircbot');
const Web = require('./web');
const fsp = fs.promises;
const TIMEOUT = 180000;
const EXTRASPACE = new RegExp('\\s+', 'g');
const NICETYPES = {
move: 'move',
udate: 'update'
}
let saveData = {
'last-sync': null,
move: [],
update: []
}
let cronjob;
let ircBot;
let savePath = process.env.SAVEPATH || path.join(__dirname, 'config', 'data.json');
fs.readFile(process.env.CONFIGPATH || path.join(__dirname, 'config', 'config.json'), async (err, data) => {
if (err) {
console.error(err);
process.exit(1);
}
else {
const config = json5.parse(data);
savePath = config.savePath || savePath;
const db = new DB(process.env.DBPATH || config.db || path.join(__dirname, 'config', 'packages.db'));
try {
saveData = JSON.parse(await fsp.readFile(savePath));
}
catch {
console.error(`Failed to read existing save data at ${savePath}`);
}
// resetting flags in case of improper shutdown
db.restoreFlags();
cronjob = cron.schedule(process.env.CRON || config.cron || '*/30 * * * *', () => {
main(config, db);
});
const web = new Web(db, config, saveData);
ircBot = new IRCBot(config);
ircBot.connect();
process.on('SIGTERM', () => {
cronjob.stop();
web.close();
ircBot.clouse();
});
}
});
async function main(config, db) {
console.log('Starting scheduled task');
cronjob.stop();
let now = dayjs();
if (!('last-sync' in saveData) || !saveData['last-sync'] || dayjs(saveData['last-sync']).isBefore(now.subtract(process.env.SYNCFREQ || config.syncfreq || 2, 'days'))) {
ircBot.close();
await updateMaintainers(config, db);
saveData['last-sync'] = now.toJSON();
await writeSaveData();
await ircBot.connect();
}
await checkupdates(config, db);
await writeSaveData();
cronjob.start();
console.log('Task complete.');
}
async function writeSaveData() {
try {
await fsp.writeFile(savePath, JSON.stringify(saveData));
}
catch {
console.error(`Failed to write save data to ${savePath}`);
}
}
async function checkupdates(config, db) {
await handleUpdates(config, db, saveData.move = await execCheckUpdates(['-m']), 'move');
await handleUpdates(config, db, saveData.update = await execCheckUpdates(['-u']), 'udate');
}
async function handleUpdates(config, db, packs, type) {
packs.forEach(v => {
let p = db.getPackage(v);
p && db.updateFlag(v, type, p[type] > 0 ? 2 : 4);
});
for (let i = 0; i < config.maintainers.length; i++) {
const m = config.maintainers[i];
const mname = typeof m === 'object' ? m.name : m;
const ircName = typeof m === 'object' ? (m.ircName || mname) : m;
const packages = db.getNewByMaintainer(mname, type);
if (typeof m === 'object') {
notify({
api: config.apprise,
urls: m.channels
}, packages, NICETYPES[type])
}
ircNotify(packages, ircName, NICETYPES[type]);
}
db.decrementFlags(type);
db.restoreFlags(type);
}
async function updateMaintainers(config, db) {
console.log('Syncing packages...');
const lastseen = (new Date()).getTime();
const maintainers = config.maintainers;
for (let i = 0; maintainers && i < maintainers.length; i++) {
let maintainer = maintainers[i];
if (typeof maintainer === 'object') {
maintainer = maintainer.name;
}
console.log(`Syncing ${maintainer}...`);
try {
(await getMaintainersPackages(maintainer)).forEach(package => db.updatePackage(package, maintainer, lastseen));
}
catch (err) {
console.error(`Failed to get packages for ${maintainer}`);
console.error(err);
}
}
console.log(`removing unused packages...`);
db.cleanOldPackages(lastseen);
console.log(`Package sync complete`);
}
function getMaintainersPackages(maintainer) {
return new Promise((resolve, reject) => {
let process = spawn('artixpkg', ['admin', 'query', '-m', maintainer]);
let timeout = setTimeout(() => {
reject('Timed out');
process.kill();
}, TIMEOUT);
let packagelist = [];
process.stdout.on('data', data => {
packagelist = packagelist.concat(data.toString().trim().split('\n'));
});
process.stderr.on('data', err => {
console.error(err.toString());
})
process.on('exit', async (code) => {
if (code === 0) {
clearTimeout(timeout);
resolve(packagelist);
}
else {
reject(code);
}
});
});
}
async function notify(apprise, packarr, type) {
if (!(packarr && packarr.length && apprise && apprise.api && apprise.urls)) {
return;
}
const packagesStr = packarr.map(p => p.package).join('\n');
for (let i = 0; i < 25; i++) {
try {
return await phin({
url: `${apprise.api}/notify/`,
method: 'POST',
data: {
title: `${packarr[0].maintainer}: packages ready to ${type}`,
body: packagesStr,
urls: apprise.urls.join(',')
}
});
}
catch (ex) {
console.error('Failed to send notification, attempt #%d', i + 1);
console.error(ex);
}
}
return null;
}
function ircNotify(packarr, maintainer, type) {
if (!(packarr && packarr.length)) {
return;
}
const packagesStr = packarr.map(p => p.package).join('\n');
for (let i = 0; i < 25; i++) {
try {
return ircBot.sendMessage(`${maintainer}: packages ready to ${type}\n${packagesStr}\n-------- EOF --------`);
}
catch (ex) {
console.error('Failed to send IRC notification, attempt #%d', i + 1);
console.error(ex);
}
}
return null;
}
function parseCheckUpdatesOutput(output) {
let packages = [];
let lines = output.split('\n');
lines.forEach(l => {
let package = l.trim().replace(EXTRASPACE, ' ');
if (package.length > 0 && package.indexOf('Package basename') < 0) {
packages.push(package.split(' ', 2)[0]);
}
});
return packages;
}
function execCheckUpdates(flags) {
return new Promise((resolve, reject) => {
let process = spawn('artix-checkupdates', flags);
let timeout = setTimeout(() => {
reject('Timed out');
process.kill();
}, TIMEOUT);
let outputstr = '';
process.stdout.on('data', data => {
outputstr += data.toString();
});
process.stderr.on('data', err => {
console.error(err.toString());
})
process.on('exit', async (code) => {
if (code === 0) {
clearTimeout(timeout);
resolve(parseCheckUpdatesOutput(outputstr));
}
else {
reject(code);
}
});
});
}

View File

@@ -1,61 +0,0 @@
const IRC = require('irc-framework');
class IRCBot {
constructor(config) {
const options = config['irc-framework'];
const aux = this._aux = config.ircClient || {};
this._channel = aux.channel;
this._messageQueue = [];
if (options) {
const bot = this._bot = new IRC.Client(options);
bot.on('sasl failed', d => console.error(d));
bot.on('notice', d => console.log(`irc:notice: ${d.message}`));
bot.on('action', d => console.log(`irc:action: ${d.message}`));
setInterval(() => this.processMessageQueue(), 2000);
}
}
connect() {
return new Promise((resolve, reject) => {
const bot = this._bot;
bot.connect();
const callback = () => {
clearTimeout(timeout);
console.log(`IRC bot ${bot.user.nick} connected.`);
bot.join(this._aux.channel, this._aux.channel_key);
bot.removeListener('registered', callback);
resolve();
};
const timeout = setTimeout(() => {
bot.removeListener('registered', callback);
reject('timeout exceeded');
}, 60000);
bot.on('registered', callback);
});
}
sendMessage(str) {
str.split('\n').forEach(line => {
this._messageQueue.push(line);
});
}
processMessageQueue() {
const bot = this._bot
let message = bot.connected && this._messageQueue.shift();
message && bot.say(this._channel, message);
}
close() {
if (this._bot.connected) {
this._bot.quit('Shutting down');
}
}
}
module.exports = IRCBot;

3387
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,41 +1,55 @@
{
"name": "artix-packy-notifier",
"version": "3.3.1",
"name": "artix-checkupdates-web",
"version": "4.1.4",
"description": "Determine packages that need attention",
"main": "index.js",
"main": "./distribution/index.js",
"type": "module",
"scripts": {
"build": "node build.js",
"watch": "node build.js --watch"
"build": "npx build-shit",
"watch": "npx build-shit --watch"
},
"repository": {
"type": "git",
"url": "git+ssh://git@gitlab.com/sanin.dev/artix-packy-notifier.git"
"url": "git+ssh://git@github.com:CorySanin/artix-checkupdates-web.git"
},
"keywords": [
"artix",
"linux",
"packages"
],
"files": [
"distribution",
"assets",
"views",
"userbar"
],
"author": "Cory Sanin",
"license": "MIT",
"bugs": {
"url": "https://gitlab.com/sanin.dev/artix-packy-notifier/issues"
"url": "https://github.com/CorySanin/artix-checkupdates-web/issues"
},
"homepage": "https://gitlab.com/sanin.dev/artix-packy-notifier#readme",
"homepage": "https://github.com/CorySanin/artix-checkupdates-web#readme",
"dependencies": {
"better-sqlite3": "9.4.0",
"dayjs": "1.11.10",
"ejs": "3.1.9",
"express": "4.18.2",
"irc-framework": "4.13.1",
"artix-checkupdates": "1.0.2",
"better-sqlite3": "12.2.0",
"dayjs": "1.11.13",
"ejs": "3.1.10",
"express": "5.1.0",
"express-useragent": "1.0.15",
"irc-framework": "4.14.0",
"json5": "2.2.3",
"node-cron": "3.0.3",
"phin": "^3.7.0",
"prom-client": "15.1.0"
"ky": "1.8.2",
"node-cron": "4.2.1",
"prom-client": "15.1.3",
"sharp": "0.34.3"
},
"devDependencies": {
"csso": "5.0.5",
"sass": "1.66.1",
"uglify-js": "3.17.4"
"@sindresorhus/tsconfig": "8.0.1",
"@types/better-sqlite3": "^7.6.13",
"@types/express": "^5.0.3",
"@types/express-useragent": "1.0.5",
"@types/node": "^24.3.0",
"forking-build-shit": "1.0.1",
"typescript": "5.9.2"
}
}

35
src/config.d.ts vendored Normal file
View File

@@ -0,0 +1,35 @@
import { } from "node:os";
export type IRCFrameworkConfig = {
host: string;
port: number;
nick: string;
}
export type AuxiliaryIRCConfig = {
channel?: string;
channel_key: string;
}
export type Maintainer = {
name: string;
channels?: string[];
ircName?: string;
}
export type MaintainerArrayElement = (string | Maintainer);
export type Config = {
webhostname: string;
apprise: string;
maintainers: MaintainerArrayElement[];
cron?: string;
syncfreq: number;
db?: string;
port?: number;
privateport?: number;
savePath?: string;
irchostname?: string;
'irc-framework'?: IRCFrameworkConfig;
ircClient?: AuxiliaryIRCConfig;
}

268
src/daemon.mts Normal file
View File

@@ -0,0 +1,268 @@
import { Checkupdates } from 'artix-checkupdates';
import { DB } from './db.mjs';
import { spawn } from 'child_process';
import ky from 'ky';
import * as path from 'path';
import * as fsp from 'node:fs/promises';
import * as cron from 'node-cron';
import dayjs from 'dayjs';
import express from 'express';
import type http from "http";
import type { Express } from "express";
import type { Config, MaintainerArrayElement } from './config.js';
import type { Category, PackageDBEntry } from './db.mjs';
const TIMEOUT = 180000;
const ORPHAN = {
"name": "orphan",
"ircName": "orphaned"
};
const NICETYPES = {
move: 'move',
udate: 'update'
};
type SaveData = {
'last-sync': string | null;
move: string[];
update: string[];
}
type AppriseConf = {
api: string;
urls: string[];
}
function notStupidParseInt(v: string | undefined): number {
return v === undefined ? NaN : parseInt(v);
}
class Daemon {
private _config: Config;
private _savePath: string;
private _locked: boolean;
private _saveData: SaveData;
private _db: DB;
private _cronjob: cron.ScheduledTask;
private _webserver: http.Server;
constructor(config: Config) {
const PROJECT_ROOT = path.resolve(import.meta.dirname, '..');
const app: Express = express();
const port = process.env['PRIVATEPORT'] || config.privateport || 8081;
this._config = config;
this._savePath = process.env['SAVEPATH'] || config.savePath || path.join(PROJECT_ROOT, 'config', 'data.json');
console.log('Written by Cory Sanin for Artix Linux');
this._locked = false;
const db = this._db = new DB(process.env['DBPATH'] || config.db || path.join(PROJECT_ROOT, 'config', 'packages.db'));
this._saveData = {
'last-sync': null,
move: [],
update: []
};
app.set('trust proxy', 1);
app.get('/healthcheck', (_, res) => {
res.send('Healthy');
});
this.readSaveData();
// resetting flags in case of improper shutdown
db.restoreFlags();
this._cronjob = cron.schedule(process.env['CRON'] || config.cron || '*/30 * * * *', () => {
this.main(this._config);
});
this._webserver = app.listen(port);
}
main = async (config: Config) => {
if (this._locked) {
return
}
this._locked = true;
console.log('Starting scheduled task');
let now = dayjs();
if (!('last-sync' in this._saveData) || !this._saveData['last-sync'] || dayjs(this._saveData['last-sync']).isBefore(now.subtract(notStupidParseInt(process.env['SYNCFREQ']) || config.syncfreq || 2, 'days'))) {
await this.updateMaintainers(config);
this._saveData['last-sync'] = now.toJSON();
await this.writeSaveData();
}
await this.checkupdates(config);
await this.writeSaveData();
this._locked = false;
console.log('Task complete.');
}
updateMaintainers = async (config: Config) => {
const db = this._db;
console.log('Syncing packages...');
const lastseen = (new Date()).getTime();
const maintainers = [...(config.maintainers || []), ORPHAN];
for (let i = 0; i < maintainers.length; i++) {
let maintainer = maintainers[i] as MaintainerArrayElement;
if (typeof maintainer === 'object') {
maintainer = maintainer.name;
}
console.log(`Syncing ${maintainer}...`);
try {
const packages: string[] = await this.getMaintainersPackages(maintainer);
for (let j = 0; j < packages.length; j++) {
db.updatePackage(packages[j] as string, maintainer, lastseen);
}
}
catch (err) {
console.error(`Failed to get packages for ${maintainer}`);
console.error(err);
}
}
console.log(`removing unused packages...`);
db.cleanOldPackages(lastseen);
console.log(`Package sync complete`);
}
checkupdates = async (config: Config) => {
const check = new Checkupdates();
try {
await this.handleUpdates(config, this._saveData.move = (await check.fetchMovable()).map(p => p.basename), 'move');
await this.handleUpdates(config, this._saveData.update = (await check.fetchUpgradable()).map(p => p.basename), 'udate');
}
catch (ex) {
console.error('Failed to check for updates:', ex);
}
}
getMaintainersPackages = (maintainer: string): Promise<string[]> => {
return new Promise((resolve, reject) => {
let process = spawn('artixpkg', ['admin', 'query', maintainer === ORPHAN.name ? '-t' : '-m', maintainer]);
let timeout = setTimeout(() => {
reject('Timed out');
process.kill();
}, TIMEOUT);
let packagelist: string[] = [];
process.stdout.on('data', data => {
packagelist = packagelist.concat(data.toString().trim().split('\n'));
});
process.stderr.on('data', err => {
console.error(err.toString());
})
process.on('exit', async (code) => {
if (code === 0) {
clearTimeout(timeout);
resolve(packagelist);
}
else {
reject(code);
}
});
});
}
handleUpdates = async (config: Config, packs: string[], type: Category) => {
const db = this._db;
packs.forEach(v => {
let p = db.getPackage(v);
p && db.updateFlag(v, type, p[type] > 0 ? 2 : 4);
});
const maintainers: MaintainerArrayElement[] = [...config.maintainers, ORPHAN];
for (let i = 0; i < maintainers.length; i++) {
const m = maintainers[i] as MaintainerArrayElement;
const mname: string = typeof m === 'object' ? m.name : m;
const ircName = typeof m === 'object' ? (m.ircName || mname) : m;
const packages = db.getNewByMaintainer(mname, type);
if (typeof m === 'object' && m.channels) {
this.notify({
api: config.apprise,
urls: m.channels
}, packages, NICETYPES[type]);
}
this.ircNotify(packages, ircName, NICETYPES[type]);
}
db.decrementFlags(type);
db.restoreFlags(type);
}
notify = async (apprise: AppriseConf, packarr: PackageDBEntry[], type: string) => {
if (!(packarr && packarr.length && apprise && apprise.api && apprise.urls)) {
return;
}
const packagesStr = packarr.map(p => p.package).join('\n');
for (let i = 0; i < 25; i++) {
try {
return await ky.post(`${apprise.api}/notify/`, {
json: {
title: `${packarr[0]?.maintainer}: packages ready to ${type}`,
body: packagesStr,
urls: apprise.urls.join(',')
}
});
}
catch (ex) {
console.error('Failed to send notification, attempt #%d', i + 1);
console.error(ex);
}
}
return null;
}
ircNotify = async (packarr: PackageDBEntry[], maintainer: string, type: string) => {
const config = this._config;
if (!(packarr && packarr.length && config['irc-framework'])) {
return;
}
const hostname = process.env['IRCHOSTNAME'] || config.irchostname || 'http://artix-notifier-irc:8081';
const packagesStr = packarr.map(p => p.package).join('\n');
for (let i = 0; i < 25; i++) {
try {
return await ky.post(`${hostname}/api/1.0/notifications`, {
json: {
message: `${maintainer}: packages ready to ${type}\n${packagesStr}\n-------- EOF --------`
}
});
}
catch (ex) {
console.error('Failed to send IRC notification, attempt #%d', i + 1);
console.error(ex);
}
}
return null;
}
readSaveData = async () => {
try {
this._saveData = JSON.parse((await fsp.readFile(this._savePath)).toString());
}
catch {
console.error(`Failed to read existing save data at ${this._savePath}`);
}
}
writeSaveData = async () => {
const config = this._config;
const hostname = process.env['WEBHOSTNAME'] || config.webhostname || 'http://artix-notifier-web:8081';
try {
await fsp.writeFile(this._savePath, JSON.stringify(this._saveData));
ky.put(`${hostname}/api/1.0/data`);
}
catch {
console.error(`Failed to write save data to ${this._savePath}`);
}
}
close = () => {
if (this._webserver) {
this._webserver.close();
}
if (this._cronjob) {
this._cronjob.stop();
}
}
}
export default Daemon;
export { Daemon };
export type { SaveData };

View File

@@ -1,10 +1,52 @@
const sqlite = require('better-sqlite3');
import Database from 'better-sqlite3';
const TABLE = 'packages';
type Category = 'move' | 'udate';
interface CommonOperations {
GET: Database.Statement;
GETNEWBYMAINTAINER: Database.Statement;
UPDATE: Database.Statement;
INCREMENT: Database.Statement;
DECREMENT: Database.Statement;
FIXFLAG: Database.Statement;
GETPACKAGESBYMAINTAINER: Database.Statement;
GETPACKAGECOUNTBYMAINTAINER: Database.Statement;
}
interface DatabaseOperations {
GETPACKAGE: Database.Statement;
ADDPACKAGE: Database.Statement;
GETPACKAGES: Database.Statement;
GETPACKAGESSTARTWITH: Database.Statement;
UPDATEMAINTAINER: Database.Statement;
GETMAINTAINERPACKAGECOUNT: Database.Statement;
REMOVEOLDPACKAGE: Database.Statement;
move: CommonOperations;
udate: CommonOperations;
}
interface PackageDBEntry {
package: string;
maintainer: string;
move: number;
udate: number;
lastseen: Date;
}
interface CountResult {
count: number;
}
class DB {
constructor(file) {
this._db = new sqlite(file);
private _db: Database.Database;
private _queries: DatabaseOperations;
constructor(file: string | Buffer) {
this._db = new Database(file);
const db = this._db;
db.pragma('journal_mode = WAL');
if (!db.prepare(`SELECT name FROM sqlite_master WHERE type='table' AND name='${TABLE}';`).get()) {
db.prepare(`CREATE TABLE ${TABLE} (package VARCHAR(128) PRIMARY KEY, maintainer VARCHAR(128), move INTEGER, udate INTEGER, lastseen DATETIME);`).run();
@@ -13,6 +55,8 @@ class DB {
this._queries = {
GETPACKAGE: db.prepare(`SELECT * FROM ${TABLE} WHERE package = @package;`),
ADDPACKAGE: db.prepare(`INSERT INTO ${TABLE} (package,maintainer,move,udate,lastseen) VALUES (@package, @maintainer, 0, 0, @lastseen);`),
GETPACKAGES: db.prepare(`SELECT package FROM ${TABLE}`),
GETPACKAGESSTARTWITH: db.prepare(`SELECT package FROM ${TABLE} WHERE package LIKE @startsWith || '%'`),
UPDATEMAINTAINER: db.prepare(`UPDATE ${TABLE} SET maintainer = @maintainer, lastseen= @lastseen WHERE package = @package`),
GETMAINTAINERPACKAGECOUNT: db.prepare(`SELECT COUNT(package) as count FROM ${TABLE} WHERE maintainer = @maintainer;`),
REMOVEOLDPACKAGE: db.prepare(`DELETE FROM ${TABLE} WHERE lastseen < @lastseen;`),
@@ -23,7 +67,7 @@ class DB {
INCREMENT: db.prepare(`UPDATE ${TABLE} SET move = move + 1 WHERE package = @package`),
DECREMENT: db.prepare(`UPDATE ${TABLE} SET move = 0 WHERE move = 1`),
FIXFLAG: db.prepare(`UPDATE ${TABLE} SET move = 1 WHERE move > 1`),
GETPACKAGESBYMAINTAINER: db.prepare(`SELECT * FROM ${TABLE} WHERE maintainer = @maintainer AND move > 0;`),
GETPACKAGESBYMAINTAINER: db.prepare(`SELECT * FROM ${TABLE} WHERE maintainer = @maintainer AND move > 0 ORDER BY package ASC;`),
GETPACKAGECOUNTBYMAINTAINER: db.prepare(`SELECT COUNT(package) as count FROM ${TABLE} WHERE maintainer = @maintainer AND move > 0;`)
},
udate: {
@@ -33,24 +77,33 @@ class DB {
INCREMENT: db.prepare(`UPDATE ${TABLE} SET udate = udate + 1 WHERE package = @package`),
DECREMENT: db.prepare(`UPDATE ${TABLE} SET udate = 0 WHERE udate = 1`),
FIXFLAG: db.prepare(`UPDATE ${TABLE} SET udate = 1 WHERE udate > 1`),
GETPACKAGESBYMAINTAINER: db.prepare(`SELECT * FROM ${TABLE} WHERE maintainer = @maintainer AND udate > 0;`),
GETPACKAGESBYMAINTAINER: db.prepare(`SELECT * FROM ${TABLE} WHERE maintainer = @maintainer AND udate > 0 ORDER BY package ASC;`),
GETPACKAGECOUNTBYMAINTAINER: db.prepare(`SELECT COUNT(package) as count FROM ${TABLE} WHERE maintainer = @maintainer AND udate > 0;`)
}
};
}
restoreFlags() {
this._queries.move.FIXFLAG.run();
this._queries.udate.FIXFLAG.run();
restoreFlags(type: Category | null = null) {
if (type !== 'udate') {
this._queries.move.FIXFLAG.run();
}
if (type !== 'move') {
this._queries.udate.FIXFLAG.run();
}
}
getPackage(pack) {
getPackage(pack: string): PackageDBEntry {
return this._queries.GETPACKAGE.get({
package: pack
});
}) as PackageDBEntry;
}
updatePackage(pack, maintainer, lastseen) {
getPackages(startsWith: string | null = null): string[] {
return ((!!startsWith) ? this._queries.GETPACKAGESSTARTWITH.all({ startsWith }) :
this._queries.GETPACKAGES.all()).map(p => (p as PackageDBEntry).package);
}
updatePackage(pack: string, maintainer: string, lastseen: number): Database.RunResult {
return this._queries[this.getPackage(pack) ? 'UPDATEMAINTAINER' : 'ADDPACKAGE'].run({
package: pack,
maintainer,
@@ -58,19 +111,19 @@ class DB {
});
}
incrementFlag(pack, type) {
incrementFlag(pack: string, type: Category): boolean {
this._queries[type].INCREMENT.run({
package: pack
});
return true;
}
decrementFlags(type) {
decrementFlags(type: Category): boolean {
this._queries[type].DECREMENT.run();
return true;
}
updateFlag(pack, type, bool) {
updateFlag(pack: string, type: Category, bool: number): boolean {
this._queries[type].UPDATE.run({
package: pack,
bool
@@ -78,41 +131,43 @@ class DB {
return true;
}
getFlag(type, bool = true) {
getFlag(type: Category, bool: boolean = true): PackageDBEntry[] {
return this._queries[type].GET.all({
bool
});
}) as PackageDBEntry[];
}
getNewByMaintainer(maintainer, type) {
getNewByMaintainer(maintainer: string, type: Category): PackageDBEntry[] {
return this._queries[type].GETNEWBYMAINTAINER.all({
maintainer
});
}) as PackageDBEntry[];
}
getPackagesByMaintainer(maintainer, type) {
getPackagesByMaintainer(maintainer: string, type: Category): PackageDBEntry[] {
return this._queries[type].GETPACKAGESBYMAINTAINER.all({
maintainer
});
}) as PackageDBEntry[];
}
getPackageCountByMaintainer(maintainer, type) {
return this._queries[type].GETPACKAGECOUNTBYMAINTAINER.get({
getPackageCountByMaintainer(maintainer: string, type: Category): number {
return (this._queries[type].GETPACKAGECOUNTBYMAINTAINER.get({
maintainer
}).count;
}) as CountResult).count;
}
cleanOldPackages(lastseen) {
cleanOldPackages(lastseen: number): Database.RunResult {
return this._queries.REMOVEOLDPACKAGE.run({
lastseen
});
}
getMaintainerPackageCount(maintainer) {
return this._queries.GETMAINTAINERPACKAGECOUNT.get({
getMaintainerPackageCount(maintainer: string): number {
return (this._queries.GETMAINTAINERPACKAGECOUNT.get({
maintainer
}).count;
}) as CountResult).count;
}
}
module.exports = DB;
export default DB;
export { DB };
export type { PackageDBEntry, Category };

29
src/index.mts Normal file
View File

@@ -0,0 +1,29 @@
import * as path from 'path';
import * as fsp from 'node:fs/promises';
import JSON5 from 'json5';
import { IRCBot } from './ircBot.mjs';
import { Daemon } from './daemon.mjs';
import { Web } from './web.mjs';
const PROJECT_ROOT = path.resolve(import.meta.dirname, '..');
const data = await fsp.readFile(process.env['CONFIG'] || path.join(PROJECT_ROOT, 'config', 'config.json'));
let config = JSON5.parse(data.toString());
let arg = process.env['COMPONENT'] || (process.execArgv && process.execArgv[0]);
if (arg === 'daemon') {
const daemon = new Daemon(config);
process.on('SIGTERM', daemon.close);
}
else if (arg === 'ircbot') {
const bot = new IRCBot(config);
bot.connect();
process.on('SIGTERM', bot.close);
}
else if (arg === 'web') {
const web = new Web(config);
process.on('SIGTERM', web.close);
}
else {
console.error('Please pass the component you wish to run.');
}

119
src/ircBot.mts Normal file
View File

@@ -0,0 +1,119 @@
import express from 'express';
import type { Config, AuxiliaryIRCConfig } from './config.js';
import type http from "http";
// @ts-ignore
import IRC from 'irc-framework';
class IRCBot {
private _aux: AuxiliaryIRCConfig | undefined;
private _channel: string | undefined;
private _bot: any;
private _enabled: boolean;
private _messageQueue: string[];
private _webserver: http.Server | undefined;
constructor(config: Config) {
const options = config['irc-framework'];
const aux = this._aux = config.ircClient || undefined;
const app = express();
const port = process.env['PRIVATEPORT'] || config.privateport || 8081;
this._channel = aux?.channel;
this._messageQueue = [];
this._enabled = !!options;
app.set('trust proxy', 1);
app.use(express.json());
app.get('/healthcheck', (_, res) => {
if (this._bot && this._bot.connected) {
res.send('healthy');
}
else {
res.status(500).send('offline');
process.exit(1);
}
});
app.post('/api/1.0/notifications', (req, res) => {
const body = req.body;
if (body && body.message) {
this.sendMessage(body.message);
res.json({
success: true
});
}
else {
res.status(400).json({
success: false,
error: 'must include `message` property in request body'
});
}
});
if (options) {
const bot = this._bot = new IRC.Client(options);
bot.on('sasl failed', (d: Error) => console.error(d));
bot.on('notice', (d: Error) => console.log(`irc:notice: ${d.message}`));
bot.on('action', (d: Error) => console.log(`irc:action: ${d.message}`));
setInterval(() => this.processMessageQueue(), 2000);
this._webserver = app.listen(port, () => console.log(`artix-checkupdates-notifier-irc running on port ${port}`));
}
else {
console.log('"ircClient" not provided in config. IRC notifications will not be delivered.');
}
}
connect(): Promise<void> {
return new Promise((resolve, reject) => {
if (this._enabled) {
const bot = this._bot;
bot.connect();
const callback = () => {
clearTimeout(timeout);
console.log(`IRC bot ${bot.user.nick} connected.`);
bot.join(this._aux?.channel, this._aux?.channel_key);
bot.removeListener('registered', callback);
resolve();
};
const timeout = setTimeout(() => {
bot.removeListener('registered', callback);
reject('timeout exceeded');
}, 60000);
bot.on('registered', callback);
}
else {
resolve();
}
});
}
sendMessage(str: string) {
(this._enabled ? str.split('\n') : []).forEach(line => {
this._messageQueue.push(line);
});
}
processMessageQueue() {
const bot = this._bot
let message = bot.connected && this._messageQueue.shift();
message && bot.say(this._channel, message);
}
close() {
if (this._webserver) {
this._webserver.close();
}
if (this._enabled && this._bot.connected) {
this._bot.quit('Shutting down');
}
}
}
export default IRCBot;
export { IRCBot };

398
src/web.mts Normal file
View File

@@ -0,0 +1,398 @@
import fs from 'fs';
import * as fsp from 'node:fs/promises';
import { DB } from './db.mjs';
import express from 'express';
import exuseragent from 'express-useragent';
import prom from 'prom-client';
import sharp from 'sharp';
import * as path from 'path';
import type http from "http";
import type { Request, Response } from "express";
import type { Details } from "express-useragent";
import type { Config } from './config.js';
import type { PackageDBEntry } from './db.mjs';
import type { SaveData } from './daemon.mjs';
const PROJECT_ROOT = path.resolve(import.meta.dirname, '..');
const VIEWOPTIONS = {
outputFunctionName: 'echo'
};
type Action = "Move" | "Update";
type WebPackageObject = {
package: string;
action: Action;
url: string;
}
type ParseablePackage = string | PackageDBEntry;
function inliner(file: string) {
return fs.readFileSync(path.join(PROJECT_ROOT, file));
}
function parsePackage(p: ParseablePackage): string {
return typeof p === 'string' ? p : p.package;
}
function packageUrl(p: ParseablePackage) {
return `https://gitea.artixlinux.org/packages/${parsePackage(p)}`;
}
function prepPackages(arr: ParseablePackage[], action: Action): WebPackageObject[] {
return arr.map(m => {
return {
package: parsePackage(m),
action,
url: packageUrl(m)
}
});
}
async function createOutlinedText(string: string, meta: sharp.Metadata, gravity: sharp.Gravity = 'west') {
const txt = sharp({
create: {
width: meta.width || 0,
height: meta.height || 0,
channels: 4,
background: { r: 0, g: 0, b: 0, alpha: 0 }
}
}).composite([
{
input: {
text: {
text: string,
font: 'Visitor TT2 BRK',
fontfile: path.join(PROJECT_ROOT, 'userbar', 'visitor', 'visitor2.ttf'),
width: meta.width || 0,
dpi: 109,
rgba: true
}
},
gravity
}
]);
const outline = await txt.clone().png().toBuffer();
const mult = gravity === 'east' ? -1 : 1;
const layers = [
{
input: (outline),
top: 1 * mult,
left: 0
},
{
input: (outline),
top: 0,
left: 1 * mult
},
{
input: (outline),
top: 1 * mult,
left: 2 * mult
},
{
input: (outline),
top: 2 * mult,
left: 1 * mult
},
{
input: (await txt.clone().linear(0, 255).png().toBuffer()),
top: 1 * mult,
left: 1 * mult
}
];
return txt.composite(layers);
}
class Web {
private _webserver: http.Server;
private _privateserver: http.Server;
constructor(options: Config) {
const db = new DB(process.env['DBPATH'] || options.db || path.join(PROJECT_ROOT, 'config', 'packages.db'));
const app = express();
const privateapp = express();
const port = process.env['PORT'] || options.port || 8080;
const privateport = process.env['PRIVATEPORT'] || options.privateport || 8081;
const METRICPREFIX = process.env['METRICPREFIX'] || 'artixpackages_';
const maintainers = (options.maintainers || []).map(m => typeof m === 'object' ? m.name : m).sort();
const savePath = process.env['SAVEPATH'] || options.savePath || path.join(PROJECT_ROOT, 'config', 'data.json');
let saveData: SaveData = {
'last-sync': null,
move: [],
update: []
};
app.set('trust proxy', 1);
app.set('view engine', 'ejs');
app.set('view options', VIEWOPTIONS);
app.use(exuseragent.express());
function sendError(req: Request, res: Response, status: number, description: string) {
console.log(`${status} (${description}): ${req.url} requested by ${req.ip} "${req.headers['user-agent']}"`);
if ((req.useragent as Details).browser === 'curl') {
res.send('404: not found\n');
return;
}
res.render('error',
{
inliner,
site: {
prefix: 'Artix Checkupdates',
suffix: 'Error'
},
status,
description
},
function (err, html) {
if (!err) {
res.status(status).send(html);
}
else {
console.error(err);
res.status(500).send(description);
}
}
);
}
async function readSave() {
saveData = JSON.parse((await fsp.readFile(savePath)).toString());
}
function renderForCurl(packages: WebPackageObject[]) {
const colHeader = 'Package basename';
const tabSize = packages.reduce((acc, cur) => Math.max(acc, cur.package?.length || 0), colHeader.length) + 4;
return `${colHeader.padEnd(tabSize, ' ')}Action\n${packages.map(p => `${p.package?.padEnd(tabSize, ' ')}${p.action}`).join('\n')}\n`;
}
app.get('/healthcheck', async (_, res) => {
res.send('Healthy');
});
app.get('/', async (req, res) => {
let packages = prepPackages(saveData.move, 'Move');
packages = packages.concat(prepPackages(saveData.update, 'Update'));
if ((req.useragent as Details).browser === 'curl') {
res.send(renderForCurl(packages));
return;
}
res.render('index',
{
inliner,
site: {
prefix: 'Artix Checkupdates',
suffix: 'Web Edition'
},
packages,
maintainers: maintainers
},
function (err, html) {
if (!err) {
res.send(html);
}
else {
console.error(err);
sendError(req, res, 500, 'Something went wrong. Try again later.');
}
}
);
});
app.get('/maintainer/:maintainer', async (req, res) => {
const maintainer = req.params.maintainer;
const packagesOwned = db.getMaintainerPackageCount(maintainer);
let packages = prepPackages(db.getPackagesByMaintainer(maintainer, 'move'), 'Move');
packages = packages.concat(prepPackages(db.getPackagesByMaintainer(maintainer, 'udate'), 'Update'));
if (packagesOwned > 0) {
if ((req.useragent as Details).browser === 'curl') {
res.send(`${maintainer}'s pending actions\n\n${renderForCurl(packages)}`);
return;
}
res.render('maintainer',
{
inliner,
site: {
prefix: 'Artix Checkupdates',
suffix: `${maintainer}'s pending actions`
},
maintainer,
packagesOwned,
packages
},
function (err, html) {
if (!err) {
res.send(html);
}
else {
console.error(err);
res.status(500).send('Something went wrong. Try again later.');
}
}
);
}
else {
sendError(req, res, 404, 'File not found');
}
});
app.get('/userbar/:maintainer.png', async (req, res) => {
const maintainer = req.params.maintainer;
const packagesOwned = db.getMaintainerPackageCount(maintainer);
if (packagesOwned > 0) {
const img = sharp(path.join(PROJECT_ROOT, 'userbar', 'userbar.png'));
const meta: sharp.Metadata = await img.metadata();
const layers = [
{
input: (await (await createOutlinedText('Artix Maintainer', meta)).png().toBuffer()),
top: 1,
left: 55
},
{
input: (await (await createOutlinedText(`${packagesOwned} packages`, meta, 'east')).png().toBuffer()),
top: 3,
left: -12
}
];
res.set('Content-Type', 'image/png')
.set('Cache-Control', 'public, max-age=172800')
.send(await img.composite(layers).png({
quality: 90,
compressionLevel: 3
}).toBuffer());
}
else {
sendError(req, res, 404, 'File not found');
}
});
app.get('/robots.txt', (_, res) => {
res.set('content-type', 'text/plain').send('User-agent: *\nDisallow: /metrics\n');
});
app.get('/api/1.0/maintainers', (req, res) => {
const acceptHeader = req.headers.accept;
res.set('Cache-Control', 'public, max-age=360');
if (acceptHeader && acceptHeader.includes('application/json')) {
res.json({
maintainers
});
}
else {
res.send(maintainers.join(' '));
}
});
app.get('/api/1.0/packages', (req, res) => {
const acceptHeader = req.headers.accept;
const startsWith = req.query['startswith'] as string;
const packages = db.getPackages(startsWith);
res.set('Cache-Control', 'public, max-age=360');
if (acceptHeader && acceptHeader.includes('application/json')) {
res.json({
packages
});
}
else {
res.send(packages.join(' '));
}
});
privateapp.put('/api/1.0/data', (_, res) => {
try {
readSave();
res.json({
success: true
});
}
catch (ex) {
console.error(ex);
res.status(500).json({
success: false,
error: 'failed to read save data'
});
}
});
const register = prom.register;
new prom.Gauge({
name: `${METRICPREFIX}pending_packages`,
help: 'Number of packages that have pending moves and updates.',
labelNames: ['maintainer', 'action'],
collect() {
maintainers.forEach(m => {
this.set({
maintainer: `${m}`,
action: 'move'
}, db.getPackageCountByMaintainer(m, 'move'));
this.set({
maintainer: `${m}`,
action: 'update'
}, db.getPackageCountByMaintainer(m, 'udate'));
});
this.set({
maintainer: 'any',
action: 'move'
}, saveData.move.length);
this.set({
maintainer: 'any',
action: 'update'
}, saveData.update.length);
}
});
new prom.Gauge({
name: `${METRICPREFIX}watched_packages`,
help: 'Number of packages being monitored for updates.',
labelNames: ['maintainer'],
collect() {
maintainers.forEach(m => {
this.set({
maintainer: `${m}`
}, db.getMaintainerPackageCount(m));
});
}
});
app.get('/metrics', async (_, res) => {
try {
res.set('Content-Type', register.contentType);
res.end(await register.metrics());
}
catch (ex) {
console.error(ex);
res.status(500).send('something went wrong.');
}
});
app.use('/assets/', express.static('assets', {
maxAge: '30d'
}));
app.use((req, res) => sendError(req, res, 404, 'File not found'));
privateapp.use('/', app);
readSave();
this._webserver = app.listen(port, () => console.log(`artix-checkupdates-web running on port ${port}`));
this._privateserver = privateapp.listen(privateport);
}
close = () => {
this._webserver.close();
this._privateserver.close();
}
}
export default Web;
export { Web };

View File

@@ -164,14 +164,14 @@ table tr td:last-child {
}
}
@media screen and (max-width:790px) {
@media screen and (max-width:910px) {
.container {
width: initial;
margin: .5em .5em;
}
}
@media screen and (max-width:660px) {
@media screen and (max-width:740px) {
header {
nav {
float: initial;

12
tsconfig.dist.json Normal file
View File

@@ -0,0 +1,12 @@
{
"extends": "./tsconfig",
"compilerOptions": {
"sourceMap": true,
"inlineSources": true,
"rootDir": "./src",
"outDir": "./distribution"
},
"include": [
"src"
]
}

10
tsconfig.json Normal file
View File

@@ -0,0 +1,10 @@
{
"extends": "@sindresorhus/tsconfig",
"compilerOptions": {
"exactOptionalPropertyTypes": true,
"esModuleInterop": true
},
"include": [
"src"
]
}

BIN
userbar/userbar.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

BIN
userbar/userbar.psd Normal file

Binary file not shown.

View File

@@ -0,0 +1,86 @@
______________________________
Visitor Created by Brian Kent
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
Thanks for Downloading Visitor.
-Visitor TT1 [.ttf]
-Visitor TT2 [.ttf]
-Visitor [7pt] [.fon]
'Visitor.fon' is a Windows Bitmap Font (.fon). This font is best
used at 7pt. To use it at larger point sizes (for images), try using
a graphics program like Photo Shop, Paint Shop Pro, or the Paint
program that comes with Windows. Type out your text at the recommended
point size [7pt], then resize the image. Set the color mode to 256
or 2 colors so the edges don't get blured when resizing, then after you
have the text to the size that you want, then change back to a higher
color mode and edit the image.
For programs that don't show Bitmap Fonts in the Font Selector, you
may be able to get the font to work by typing in:
visitor -brk-
The TTF versions were created different ways. TT1 was created from
within FontLab and TT2 was created in Illustrator then imported into
FontLab. I didn't know which one to include so I just included both.
If you have any questions or comments, you can e-mail me at
kentpw@norwich.net
You can visit my Homepage <<3C>NIGMA GAMES & FONTS> at
http://www.aenigmafonts.com/
____________
!!! NOTE !!!
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
This font has been updated! I've edited the (BRK) in the font name
to just BRK. It seems that Adobe Illustrator and web pages with CSS
don't like fonts with ( and ) in their name.
________________
INSTALLING FONTS
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
There's a couple of ways to install Fonts. The 'easy' way to
install fonts is to just Unzip/place the font file(s) into your
Windows\Fonts directory (I always use this method). If you're unable
to do it the 'easy' way, then try to do it this way (for Windows
95/98/NT):
1] Unzip the Font(s) to a folder (or somewhere, just remember where
you unzipped it) on your Computer.
2] Next, click on the START button, then select SETTINGS then
CONTROL PANEL.
3] When the Control Panel Window pops up, Double Click on FONTS.
4] When the FONTS window pops up, select File then Install New Font...
5] A Add Fonts window will pop up, just go to the folder that you
unzipped the Font(s) to, select the Font(s) and then click on OK.
Now the Font(s) are installed.
Now you can use the Font(s) in programs the utilize Fonts. Make
sure that you install the font(s) first, then open up your apps
(so the app will recognize the font). Sometimes you'll have to
wait until you computer 'auto-refreshes' for programs to recognize
fonts (Windows is sometimes slow to do that). You can refresh your
computer quicker by going into Windows Explorer -or- My Computer and
press F5 (or in the menubar select VIEW then REFRESH).
__________
DISCLAIMER
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
-The font(s) in this zip file were created by me (Brian Kent). All
of my Fonts are Freeware, you can use them any way you want to
(Personal use, Commercial use, or whatever).
-If you have a Font related site and would like to offer my fonts on
your site, go right ahead. All I ask is that you keep this text file
intact with the Font.
-You may not Sell or Distribute my Fonts for profit or alter them in
any way without asking me first. [e-mail - kentpw@norwich.net]

Binary file not shown.

Binary file not shown.

View File

@@ -3,7 +3,7 @@
<ul>
<li>© <%= (new Date()).getFullYear() %> Artix Linux</li>
<li>Developed by Cory Sanin</li>
<li><a href="https://gitea.artixlinux.org/corysanin/artix-packy-notifier">Source</a></li>
<li><a href="https://github.com/CorySanin/artix-checkupdates-web">Source</a></li>
</ul>
</footer>
</div>

View File

@@ -9,6 +9,6 @@
<meta name="apple-mobile-web-app-title" content="Artix Checkupdates">
<meta name="application-name" content="Artix Checkupdates">
<meta name="theme-color" content="#212121">
<link rel="stylesheet" href="/assets/css/styles.css?v=2">
<link rel="stylesheet" href="/assets/css/styles.css?v=3">
<link rel="shortcut icon" href="/assets/svg/artix_logo.svg">
</head>

View File

@@ -10,6 +10,7 @@
<li><a href="https://forum.artixlinux.org/">Forum</a></li>
<li><a href="https://wiki.artixlinux.org/">Wiki</a></li>
<li><a href="https://gitea.artixlinux.org/explore/repos">Sources</a></li>
<li><a href="https://packages.artixlinux.org/">Packages</a></li>
</ul>
</nav>
</header>

View File

@@ -9,8 +9,9 @@
<% maintainers && maintainers.forEach(m => { %>
<li><a href="/maintainer/<%= m %>"><%= m %></a></li>
<% }); %>
<li><a href="/maintainer/orphan">Orphan Packages</a></li>
</ul>
<h2>All Pending</h2>
<h2>All Pending (<%= (packages && packages.length) || 0 %> packages)</h2>
<table>
<tr>
<th>Package</th>

View File

@@ -3,10 +3,20 @@
<body>
<%- include("header", locals) %>
<div class="container bg">
<% if (maintainer === 'orphan') { %>
<h1>Orphaned Packages with Pending Operations</h1>
<p>
There are <a href="https://gitea.artixlinux.org/explore/repos?q=<%= maintainer %>&topic=1"><%= packagesOwned %> packages</a> without a maintainer.
</p>
<% } else { %>
<h1><%= maintainer %>'s Operations</h1>
<p>
<%= maintainer %> owns <a href="https://gitea.artixlinux.org/explore/repos?q=maintainer-<%= maintainer %>&topic=1"><%= packagesOwned %> packages</a>.
</p>
<% } %>
<p>
<%= (packages && packages.length) || 0 %> of which require attention.
</p>
<table>
<tr>
<th>Package</th>
@@ -14,10 +24,11 @@
</tr>
<% packages && packages.forEach(p => { %>
<tr>
<td><a href="<%= p.url %>"><%= p.package.package %></a></td>
<td><a href="<%= p.url %>"><%= p.package %></a></td>
<td><%= p.action %></td>
</tr>
<% }); %>
</table>
</div>
<%- include("footer", locals) %>
</body>

203
web.js
View File

@@ -1,203 +0,0 @@
const express = require('express');
const prom = require('prom-client');
const fs = require('fs');
const path = require('path');
const PROJECT_ROOT = __dirname;
const VIEWOPTIONS = {
outputFunctionName: 'echo'
};
const NAMECOMPLIANCE = [
p => p.replace(/([a-zA-Z0-9]+)\+([a-zA-Z]+)/g, '$1-$2'),
p => p.replace(/\+/g, "plus"),
p => p.replace(/[^a-zA-Z0-9_\-\.]/g, "-"),
p => p.replace(/[_\-]{2,}/g, "-")
]
function inliner(file) {
return fs.readFileSync(path.join(PROJECT_ROOT, file));
}
function packageUrl(p) {
let packagename = typeof p === 'string' ? p : p.package;
return `https://gitea.artixlinux.org/packages/${NAMECOMPLIANCE.reduce((s, fn) => fn(s), packagename)}`;
}
function prepPackages(arr, action) {
return arr.map(m => {
return {
package: m,
action,
url: packageUrl(m)
}
});
}
class Web {
constructor(db, options, savedata) {
const app = express();
const port = process.env.PORT || options.port || 8080;
const METRICPREFIX = process.env.METRICPREFIX || 'artixpackages_';
const maintainers = this._maintainers = options.maintainers.map(m => typeof m === 'object' ? m.name : m).sort();
app.set('trust proxy', 1);
app.set('view engine', 'ejs');
app.set('view options', VIEWOPTIONS);
function sendError(req, res, status, description) {
console.log(`${status} (${description}): ${req.url} requested by ${req.ip} "${req.headers['user-agent']}"`);
res.render('error',
{
inliner,
site: {
prefix: 'Artix Checkupdates',
suffix: 'Error'
},
status,
description
},
function (err, html) {
if (!err) {
res.status(status).send(html);
}
else {
console.error(err);
res.status(500).send(description);
}
}
);
}
app.get('/healthcheck', async (_, res) => {
res.send('Healthy');
});
app.get('/', async (_, res) => {
let packages = prepPackages(savedata.move, 'Move');
packages = packages.concat(prepPackages(savedata.update, 'Update'));
res.render('index',
{
inliner,
site: {
prefix: 'Artix Checkupdates',
suffix: 'Web Edition'
},
packages,
maintainers: maintainers
},
function (err, html) {
if (!err) {
res.send(html);
}
else {
console.error(err);
sendError(req, res, 500, 'Something went wrong. Try again later.');
}
}
);
});
app.get('/maintainer/:maintainer', async (req, res) => {
const maintainer = req.params.maintainer;
const packagesOwned = db.getMaintainerPackageCount(maintainer);
let packages = prepPackages(db.getPackagesByMaintainer(maintainer, 'move'), 'Move');
packages = packages.concat(prepPackages(db.getPackagesByMaintainer(maintainer, 'udate'), 'Update'));
if (packagesOwned > 0) {
res.render('maintainer',
{
inliner,
site: {
prefix: 'Artix Checkupdates',
suffix: `${maintainer}'s pending actions`
},
maintainer,
packagesOwned,
packages
},
function (err, html) {
if (!err) {
res.send(html);
}
else {
console.error(err);
res.status(500).send('Something went wrong. Try again later.');
}
}
);
}
else {
sendError(req, res, 404, 'File not found');
}
});
app.get('/robots.txt', (_, res) => {
res.set('content-type', 'text/plain').send('User-agent: *\nDisallow: /metrics\n');
});
const register = prom.register;
new prom.Gauge({
name: `${METRICPREFIX}pending_packages`,
help: 'Number of packages that have pending moves and updates.',
labelNames: ['maintainer', 'action'],
collect() {
maintainers.forEach(m => {
this.set({
maintainer: `${m}`,
action: 'move'
}, db.getPackageCountByMaintainer(m, 'move'));
this.set({
maintainer: `${m}`,
action: 'update'
}, db.getPackageCountByMaintainer(m, 'udate'));
});
this.set({
maintainer: 'any',
action: 'move'
}, savedata.move.length);
this.set({
maintainer: 'any',
action: 'update'
}, savedata.update.length);
}
});
new prom.Gauge({
name: `${METRICPREFIX}watched_packages`,
help: 'Number of packages being monitored for updates.',
labelNames: ['maintainer'],
collect() {
maintainers.forEach(m => {
this.set({
maintainer: `${m}`
}, db.getMaintainerPackageCount(m));
});
}
});
app.get('/metrics', async (_, res) => {
try {
res.set('Content-Type', register.contentType);
res.end(await register.metrics());
}
catch (ex) {
console.error(err);
res.status(500).send('something went wrong.');
}
});
app.use('/assets/', express.static('assets', {
maxAge: '30d'
}));
app.use((req, res) => sendError(req, res, 404, 'File not found'));
this._webserver = app.listen(port, () => console.log(`artix-packy-notifier-web running on port ${port}`));
}
close = () => {
this._webserver.close();
}
}
module.exports = Web;