Compare commits
12 Commits
Author | SHA1 | Date | |
---|---|---|---|
8ca4e2105d | |||
f3b63d5cbd | |||
1f54eae84d | |||
ee29453824 | |||
9ffcd0b5ee | |||
7410c7ca0c | |||
6db2c2d683 | |||
a9191e84a0 | |||
4a4e3d9614 | |||
66f45cae07 | |||
91186f29ff | |||
e148e79195 |
13
Dockerfile
13
Dockerfile
@@ -1,4 +1,4 @@
|
|||||||
FROM artixlinux/artixlinux:devel as build-env
|
FROM artixlinux/artixlinux:base-devel as build-env
|
||||||
|
|
||||||
WORKDIR /usr/notifier
|
WORKDIR /usr/notifier
|
||||||
|
|
||||||
@@ -14,11 +14,11 @@ RUN npm run-script build && \
|
|||||||
npm ci --only=production
|
npm ci --only=production
|
||||||
|
|
||||||
|
|
||||||
FROM artixlinux/artixlinux:devel as deploy
|
FROM artixlinux/artixlinux:base-devel as deploy
|
||||||
|
|
||||||
VOLUME /usr/notifier/config
|
VOLUME /usr/notifier/config
|
||||||
WORKDIR /usr/notifier
|
WORKDIR /usr/notifier
|
||||||
HEALTHCHECK --timeout=3s \
|
HEALTHCHECK --timeout=15m \
|
||||||
CMD curl --fail http://localhost:8080/healthcheck || exit 1
|
CMD curl --fail http://localhost:8080/healthcheck || exit 1
|
||||||
|
|
||||||
EXPOSE 8080
|
EXPOSE 8080
|
||||||
@@ -29,7 +29,10 @@ RUN pacman -Sy --noconfirm curl artools-pkg artix-checkupdates git nodejs npm op
|
|||||||
|
|
||||||
COPY --from=build-env /usr/notifier /usr/notifier
|
COPY --from=build-env /usr/notifier /usr/notifier
|
||||||
|
|
||||||
RUN mkdir -p ./config /home/artix/.config/artix-checkupdates /home/artix/.config/artools && \
|
RUN mkdir -p ./config /home/artix/.config/artix-checkupdates \
|
||||||
|
/home/artix/.config/artools /home/artix/.cache/artix-checkupdates && \
|
||||||
|
ln -sf /usr/notifier/config/artools-pkg.conf /home/artix/.config/artools/artools-pkg.conf && \
|
||||||
|
ln -sf /usr/notifier/config/artix-checkupdates.conf /home/artix/.config/artix-checkupdates/config && \
|
||||||
chown -R artix:artix /home/artix/ && \
|
chown -R artix:artix /home/artix/ && \
|
||||||
chown -R artix:artix .
|
chown -R artix:artix .
|
||||||
|
|
||||||
@@ -41,4 +44,4 @@ ENV ARTIX_REPOS="system-goblins,world-goblins,galaxy-goblins,lib32-goblins,syste
|
|||||||
ENV ARCH_REPOS="core-staging,extra-staging,multilib-staging,core-testing,extra-testing,multilib-testing,core,extra,multilib"
|
ENV ARCH_REPOS="core-staging,extra-staging,multilib-staging,core-testing,extra-testing,multilib-testing,core,extra,multilib"
|
||||||
ENV GITEA_TOKEN="CHANGEME"
|
ENV GITEA_TOKEN="CHANGEME"
|
||||||
|
|
||||||
CMD ./startup.sh
|
CMD [ "node", "index.js"]
|
65
README.md
65
README.md
@@ -1,25 +1,58 @@
|
|||||||
# artix-packy-notifier
|
# artix-packy-notifier
|
||||||
|
|
||||||
Notify me when one of my packages needs maintaining
|
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
|
||||||
|
and publishes prometheus metrics.
|
||||||
|
|
||||||
mount a folder to `/usr/volume`.
|
## configuration
|
||||||
|
|
||||||
Inside the volume, create a `packages.json` with the following schema:
|
create `config/config.json`:
|
||||||
|
|
||||||
| Variable | Description |
|
| Variable | Description |
|
||||||
|-----------------|-----------------------------------------------------------------------------------------------------------------------|
|
|-----------------|-----------------------------------------------------------------------------------------------------------------------|
|
||||||
| PREVIOUS | The path to store the generated list of actionable packages. Defaults to `previous.json` in the mounted volume. |
|
| apprise | The URL of the Apprise instance for sending notifications |
|
||||||
| packages | An array of packages to look for pending operations for. |
|
| maintainers | Array of maintainer names as strings or objects containing the `name` of the maintainer and a list of `channels` to send notifications to |
|
||||||
| writeAllPending | Boolean. If all pending packages should be included in the PREVIOUS file. Provided as `allPackages` and `allMovable`. |
|
| cron | The cron schedule for when the application should check for pending operations via [artix-checkupdates](https://gitea.artixlinux.org/artix/artix-checkupdates) |
|
||||||
| apprise.api | The url of the Apprise server to use for sending notifications. For example, "http://192.168.1.123:8000" |
|
| syncfreq | How often (in days) should the application sync package ownership from Gitea |
|
||||||
| apprise.urls | An array of Apprise destination URLs to deliver notifications to. For example, "tgram://bot-token/chat-id" |
|
| port | What port to run the webserver on (defaults to 8080) |
|
||||||
|
| savePath | Location of auxiliary save data (defaults to `config/data.db`) |
|
||||||
|
| db | Location of the SQLite DB (defaults to `config/packages.db`) |
|
||||||
|
| irc-framework | The options to feed into [irc-framework](https://github.com/kiwiirc/irc-framework/blob/master/docs/clientapi.md) |
|
||||||
|
| ircClient | Auxilary config data for the IRC bot. For now, it takes `ircClient.channel` and optionally `ircClient.channel_key` |
|
||||||
|
|
||||||
The following environment variables should be supplied.
|
Note that the IRC bot needs to be exempt from excess flooding. The following command permanently voices a bot on Libera.chat:
|
||||||
|
```
|
||||||
|
/msg ChanServ FLAGS #example artix-update-bot +V
|
||||||
|
```
|
||||||
|
If the channel is intended only for the bot to broadcast, consider setting the channel mode to "moderated":
|
||||||
|
```
|
||||||
|
/mode +m #example
|
||||||
|
```
|
||||||
|
|
||||||
| Variable | Description |
|
## How to run
|
||||||
|--------------|--------------------------------------------|
|
|
||||||
| CRON | The cron schedule for checking for updates |
|
```
|
||||||
| ARTIX_MIRROR | The Artix mirror to use |
|
npm install
|
||||||
| ARCH_MIRROR | The Arch mirror to use |
|
node index.js
|
||||||
| ARTIX_REPOS | The Artix repos to check |
|
```
|
||||||
| ARCH_REPOS | The Arch repos to check |
|
|
||||||
|
## Docker Setup
|
||||||
|
|
||||||
|
Image : `registry.gitlab.com/sanin.dev/artix-packy-notifier`
|
||||||
|
|
||||||
|
mount a folder to `/usr/notifier/config`.
|
||||||
|
|
||||||
|
Include a `config.json` as described above.
|
||||||
|
|
||||||
|
Include `artools-pkg.conf`:
|
||||||
|
```
|
||||||
|
GIT_TOKEN='YOUR-GITEA-TOKEN-HERE'
|
||||||
|
```
|
||||||
|
|
||||||
|
Include `artix-checkupdates.conf`:
|
||||||
|
```
|
||||||
|
ARTIX_MIRROR=https://example.com/%s/os/x86_64
|
||||||
|
ARCH_MIRROR=https://example.com/%s/os/x86_64
|
||||||
|
ARTIX_REPOS=system-goblins,world-goblins,galaxy-goblins,lib32-goblins,system-gremlins,world-gremlins,galaxy-gremlins,lib32-gremlins,system,world,galaxy,lib32
|
||||||
|
ARCH_REPOS=core-staging,extra-staging,multilib-staging,core-testing,extra-testing,multilib-testing,core,extra,multilib
|
||||||
|
```
|
@@ -16,7 +16,7 @@
|
|||||||
<linearGradient xlink:href="#b" id="d" x1="105.834" x2="80.209" y1="15.354" y2="30.531" gradientTransform="translate(-56.383 115.378)" gradientUnits="userSpaceOnUse"/>
|
<linearGradient xlink:href="#b" id="d" x1="105.834" x2="80.209" y1="15.354" y2="30.531" gradientTransform="translate(-56.383 115.378)" gradientUnits="userSpaceOnUse"/>
|
||||||
<linearGradient xlink:href="#a" id="c" x1="75.543" x2="81.2" y1="145.986" y2="143.227" gradientTransform="translate(-16.572 -7.109)" gradientUnits="userSpaceOnUse"/>
|
<linearGradient xlink:href="#a" id="c" x1="75.543" x2="81.2" y1="145.986" y2="143.227" gradientTransform="translate(-16.572 -7.109)" gradientUnits="userSpaceOnUse"/>
|
||||||
</defs>
|
</defs>
|
||||||
<path fill="#10a0cc" stroke-width=".1" d="m23.362 0-8.034 16.474 22.112 12.39zM12.901 21.45.574 46.726l36.578-15.111zm26.955 12.368L28.32 40.441l17.832 6.284z"/>
|
<path class="artix-logo-base" fill="#10a0cc" stroke-width=".1" d="m23.362 0-8.034 16.474 22.112 12.39zM12.901 21.45.574 46.726l36.578-15.111zm26.955 12.368L28.32 40.441l17.832 6.284z"/>
|
||||||
<path fill="url(#c)" stroke-width=".265" d="m58.971 138.877 4.138-5.876 6.295 12.908z" transform="translate(-23.253 -99.183)"/>
|
<path fill="url(#c)" stroke-width=".265" d="m58.971 138.877 4.138-5.876 6.295 12.908z" transform="translate(-23.253 -99.183)"/>
|
||||||
<path fill="url(#d)" stroke-width=".265" d="m23.826 145.909 25.626-15.177 10.952.065z" transform="translate(-23.253 -99.183)"/>
|
<path fill="url(#d)" stroke-width=".265" d="m23.826 145.909 25.626-15.177 10.952.065z" transform="translate(-23.253 -99.183)"/>
|
||||||
<path fill="url(#e)" stroke-width=".265" d="m60.693 128.047-22.112-12.39 5.744-2.213z" transform="translate(-23.253 -99.183)"/>
|
<path fill="url(#e)" stroke-width=".265" d="m60.693 128.047-22.112-12.39 5.744-2.213z" transform="translate(-23.253 -99.183)"/>
|
||||||
|
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 2.4 KiB |
123
index.js
123
index.js
@@ -1,16 +1,23 @@
|
|||||||
const path = require('path');
|
const path = require('path');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
const os = require('os');
|
||||||
const spawn = require('child_process').spawn;
|
const spawn = require('child_process').spawn;
|
||||||
const cron = require('node-cron');
|
const cron = require('node-cron');
|
||||||
const dayjs = require('dayjs');
|
const dayjs = require('dayjs');
|
||||||
const json5 = require('json5');
|
const json5 = require('json5');
|
||||||
const phin = require('phin');
|
const phin = require('phin');
|
||||||
const DB = require('./db');
|
const DB = require('./db');
|
||||||
|
const IRCBot = require('./ircbot');
|
||||||
const Web = require('./web');
|
const Web = require('./web');
|
||||||
const fsp = fs.promises;
|
const fsp = fs.promises;
|
||||||
|
|
||||||
const TIMEOUT = 180000;
|
const TIMEOUT = 180000;
|
||||||
|
const ORPHAN = {
|
||||||
|
"name": "orphan",
|
||||||
|
"ircName": "orphaned"
|
||||||
|
};
|
||||||
const EXTRASPACE = new RegExp('\\s+', 'g');
|
const EXTRASPACE = new RegExp('\\s+', 'g');
|
||||||
|
const CHECKUPDATESCACHE = path.join(os.homedir(), '.cache', 'artix-checkupdates');
|
||||||
const NICETYPES = {
|
const NICETYPES = {
|
||||||
move: 'move',
|
move: 'move',
|
||||||
udate: 'update'
|
udate: 'update'
|
||||||
@@ -22,7 +29,8 @@ let saveData = {
|
|||||||
update: []
|
update: []
|
||||||
}
|
}
|
||||||
|
|
||||||
let cronjob;
|
let ircBot;
|
||||||
|
let locked = false;
|
||||||
|
|
||||||
let savePath = process.env.SAVEPATH || path.join(__dirname, 'config', 'data.json');
|
let savePath = process.env.SAVEPATH || path.join(__dirname, 'config', 'data.json');
|
||||||
|
|
||||||
@@ -32,6 +40,7 @@ fs.readFile(process.env.CONFIGPATH || path.join(__dirname, 'config', 'config.jso
|
|||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
console.log('Written by Cory Sanin for Artix Linux');
|
||||||
const config = json5.parse(data);
|
const config = json5.parse(data);
|
||||||
savePath = config.savePath || savePath;
|
savePath = config.savePath || savePath;
|
||||||
const db = new DB(process.env.DBPATH || config.db || path.join(__dirname, 'config', 'packages.db'));
|
const db = new DB(process.env.DBPATH || config.db || path.join(__dirname, 'config', 'packages.db'));
|
||||||
@@ -46,26 +55,39 @@ fs.readFile(process.env.CONFIGPATH || path.join(__dirname, 'config', 'config.jso
|
|||||||
// resetting flags in case of improper shutdown
|
// resetting flags in case of improper shutdown
|
||||||
db.restoreFlags();
|
db.restoreFlags();
|
||||||
|
|
||||||
cronjob = cron.schedule(process.env.CRON || config.cron || '*/30 * * * *', () => {
|
let cronjob = cron.schedule(process.env.CRON || config.cron || '*/30 * * * *', () => {
|
||||||
main(config, db);
|
main(config, db);
|
||||||
});
|
});
|
||||||
|
|
||||||
process.on('SIGTERM', (new Web(db, config, saveData)).close);
|
const web = new Web(db, config, saveData);
|
||||||
|
ircBot = new IRCBot(config);
|
||||||
|
ircBot.connect();
|
||||||
|
|
||||||
|
process.on('SIGTERM', () => {
|
||||||
|
cronjob.stop();
|
||||||
|
web.close();
|
||||||
|
ircBot.close();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
async function main(config, db) {
|
async function main(config, db) {
|
||||||
|
if (locked) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
locked = true;
|
||||||
console.log('Starting scheduled task');
|
console.log('Starting scheduled task');
|
||||||
cronjob.stop();
|
|
||||||
let now = dayjs();
|
let now = dayjs();
|
||||||
if (!('last-sync' in saveData) || !saveData['last-sync'] || dayjs(saveData['last-sync']).isBefore(now.subtract(3, 'days'))) {
|
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);
|
await updateMaintainers(config, db);
|
||||||
saveData['last-sync'] = now.toJSON();
|
saveData['last-sync'] = now.toJSON();
|
||||||
await writeSaveData();
|
await writeSaveData();
|
||||||
|
await ircBot.connect();
|
||||||
}
|
}
|
||||||
await checkupdates(config, db);
|
await checkupdates(config, db);
|
||||||
await writeSaveData();
|
await writeSaveData();
|
||||||
cronjob.start();
|
locked = false;
|
||||||
console.log('Task complete.');
|
console.log('Task complete.');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,8 +101,13 @@ async function writeSaveData() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function checkupdates(config, db) {
|
async function checkupdates(config, db) {
|
||||||
await handleUpdates(config, db, saveData.move = await execCheckUpdates(['-m']), 'move');
|
try {
|
||||||
await handleUpdates(config, db, saveData.update = await execCheckUpdates(['-u']), 'udate');
|
await handleUpdates(config, db, saveData.move = await execCheckUpdates(['-m']), 'move');
|
||||||
|
await handleUpdates(config, db, saveData.update = await execCheckUpdates(['-u']), 'udate');
|
||||||
|
}
|
||||||
|
catch (ex) {
|
||||||
|
console.error('Failed to check for updates:', ex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleUpdates(config, db, packs, type) {
|
async function handleUpdates(config, db, packs, type) {
|
||||||
@@ -88,15 +115,19 @@ async function handleUpdates(config, db, packs, type) {
|
|||||||
let p = db.getPackage(v);
|
let p = db.getPackage(v);
|
||||||
p && db.updateFlag(v, type, p[type] > 0 ? 2 : 4);
|
p && db.updateFlag(v, type, p[type] > 0 ? 2 : 4);
|
||||||
});
|
});
|
||||||
|
const maintainers = [...config.maintainers, ORPHAN];
|
||||||
for (let i = 0; i < config.maintainers.length; i++) {
|
for (let i = 0; i < maintainers.length; i++) {
|
||||||
let m = config.maintainers[i];
|
const m = maintainers[i];
|
||||||
if (typeof m === 'object') {
|
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' && m.channels) {
|
||||||
notify({
|
notify({
|
||||||
api: config.apprise,
|
api: config.apprise,
|
||||||
urls: m.channels
|
urls: m.channels
|
||||||
}, db.getNewByMaintainer(m.name, type), NICETYPES[type])
|
}, packages, NICETYPES[type])
|
||||||
}
|
}
|
||||||
|
ircNotify(packages, ircName, NICETYPES[type]);
|
||||||
}
|
}
|
||||||
|
|
||||||
db.decrementFlags(type);
|
db.decrementFlags(type);
|
||||||
@@ -106,15 +137,20 @@ async function handleUpdates(config, db, packs, type) {
|
|||||||
async function updateMaintainers(config, db) {
|
async function updateMaintainers(config, db) {
|
||||||
console.log('Syncing packages...');
|
console.log('Syncing packages...');
|
||||||
const lastseen = (new Date()).getTime();
|
const lastseen = (new Date()).getTime();
|
||||||
const maintainers = config.maintainers;
|
const maintainers = [...(config.maintainers || []), ORPHAN];
|
||||||
for (let i = 0; maintainers && i < maintainers.length; i++) {
|
for (let i = 0; i < maintainers.length; i++) {
|
||||||
let maintainer = maintainers[i];
|
let maintainer = maintainers[i];
|
||||||
if (typeof maintainer === 'object') {
|
if (typeof maintainer === 'object') {
|
||||||
maintainer = maintainer.name;
|
maintainer = maintainer.name;
|
||||||
}
|
}
|
||||||
console.log(`Syncing ${maintainer}...`);
|
console.log(`Syncing ${maintainer}...`);
|
||||||
try {
|
try {
|
||||||
(await getMaintainersPackages(maintainer)).forEach(package => db.updatePackage(package, maintainer, lastseen));
|
const packages = await getMaintainersPackages(maintainer);
|
||||||
|
for (let j = 0; j < packages.length; j++) {
|
||||||
|
const package = packages[j];
|
||||||
|
db.updatePackage(package, maintainer, lastseen);
|
||||||
|
await asyncSleep(50);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
console.error(`Failed to get packages for ${maintainer}`);
|
console.error(`Failed to get packages for ${maintainer}`);
|
||||||
@@ -128,7 +164,7 @@ async function updateMaintainers(config, db) {
|
|||||||
|
|
||||||
function getMaintainersPackages(maintainer) {
|
function getMaintainersPackages(maintainer) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
let process = spawn('artixpkg', ['admin', 'query', '-m', maintainer]);
|
let process = spawn('artixpkg', ['admin', 'query', maintainer === ORPHAN.name ? '-t' : '-m', maintainer]);
|
||||||
let timeout = setTimeout(() => {
|
let timeout = setTimeout(() => {
|
||||||
reject('Timed out');
|
reject('Timed out');
|
||||||
process.kill();
|
process.kill();
|
||||||
@@ -153,9 +189,10 @@ function getMaintainersPackages(maintainer) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function notify(apprise, packarr, type) {
|
async function notify(apprise, packarr, type) {
|
||||||
if (!(packarr && packarr.length)) {
|
if (!(packarr && packarr.length && apprise && apprise.api && apprise.urls)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
const packagesStr = packarr.map(p => p.package).join('\n');
|
||||||
for (let i = 0; i < 25; i++) {
|
for (let i = 0; i < 25; i++) {
|
||||||
try {
|
try {
|
||||||
return await phin({
|
return await phin({
|
||||||
@@ -163,7 +200,7 @@ async function notify(apprise, packarr, type) {
|
|||||||
method: 'POST',
|
method: 'POST',
|
||||||
data: {
|
data: {
|
||||||
title: `${packarr[0].maintainer}: packages ready to ${type}`,
|
title: `${packarr[0].maintainer}: packages ready to ${type}`,
|
||||||
body: packarr.map(p => p.package).join('\n'),
|
body: packagesStr,
|
||||||
urls: apprise.urls.join(',')
|
urls: apprise.urls.join(',')
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -176,6 +213,23 @@ async function notify(apprise, packarr, type) {
|
|||||||
return null;
|
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) {
|
function parseCheckUpdatesOutput(output) {
|
||||||
let packages = [];
|
let packages = [];
|
||||||
let lines = output.split('\n');
|
let lines = output.split('\n');
|
||||||
@@ -188,28 +242,47 @@ function parseCheckUpdatesOutput(output) {
|
|||||||
return packages;
|
return packages;
|
||||||
}
|
}
|
||||||
|
|
||||||
function execCheckUpdates(flags) {
|
async function cleanUpLockfiles() {
|
||||||
|
try {
|
||||||
|
await fsp.rm(CHECKUPDATESCACHE, { recursive: true, force: true });
|
||||||
|
}
|
||||||
|
catch (ex) {
|
||||||
|
console.error('Failed to remove the artix-checkupdates cache directory:', ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function execCheckUpdates(flags, errCallback) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
let process = spawn('artix-checkupdates', flags);
|
let process = spawn('artix-checkupdates', flags);
|
||||||
let timeout = setTimeout(() => {
|
let timeout = setTimeout(async () => {
|
||||||
|
process.kill() && await cleanUpLockfiles();
|
||||||
reject('Timed out');
|
reject('Timed out');
|
||||||
process.kill();
|
|
||||||
}, TIMEOUT);
|
}, TIMEOUT);
|
||||||
let outputstr = '';
|
let outputstr = '';
|
||||||
|
let errorOutput = '';
|
||||||
process.stdout.on('data', data => {
|
process.stdout.on('data', data => {
|
||||||
outputstr += data.toString();
|
outputstr += data.toString();
|
||||||
});
|
});
|
||||||
process.stderr.on('data', err => {
|
process.stderr.on('data', err => {
|
||||||
console.error(err.toString());
|
const errstr = err.toString();
|
||||||
|
errorOutput += `${errstr}, `;
|
||||||
|
console.error(errstr);
|
||||||
})
|
})
|
||||||
process.on('exit', async (code) => {
|
process.on('exit', async (code) => {
|
||||||
if (code === 0) {
|
if (code === 0 && errorOutput.length === 0) {
|
||||||
clearTimeout(timeout);
|
clearTimeout(timeout);
|
||||||
resolve(parseCheckUpdatesOutput(outputstr));
|
resolve(parseCheckUpdatesOutput(outputstr));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
reject(code);
|
errorOutput.includes('unable to lock database') && cleanUpLockfiles();
|
||||||
|
reject((code && `exited with ${code}`) || errorOutput);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function asyncSleep(ms) {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
setTimeout(resolve, ms);
|
||||||
|
});
|
||||||
}
|
}
|
70
ircbot.js
Normal file
70
ircbot.js
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
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 = [];
|
||||||
|
this._enabled = !!options;
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
console.log('"ircClient" not provided in config. IRC notifications will not be delivered.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
connect() {
|
||||||
|
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) {
|
||||||
|
(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._enabled && this._bot.connected) {
|
||||||
|
this._bot.quit('Shutting down');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = IRCBot;
|
1367
package-lock.json
generated
1367
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
12
package.json
12
package.json
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "artix-packy-notifier",
|
"name": "artix-packy-notifier",
|
||||||
"version": "3.0.0",
|
"version": "3.4.1",
|
||||||
"description": "Determine packages that need attention",
|
"description": "Determine packages that need attention",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
@@ -23,18 +23,20 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://gitlab.com/sanin.dev/artix-packy-notifier#readme",
|
"homepage": "https://gitlab.com/sanin.dev/artix-packy-notifier#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"better-sqlite3": "9.4.0",
|
"better-sqlite3": "9.4.3",
|
||||||
"dayjs": "1.11.10",
|
"dayjs": "1.11.10",
|
||||||
"ejs": "3.1.9",
|
"ejs": "3.1.9",
|
||||||
"express": "4.18.2",
|
"express": "4.19.1",
|
||||||
|
"irc-framework": "4.13.1",
|
||||||
"json5": "2.2.3",
|
"json5": "2.2.3",
|
||||||
"node-cron": "3.0.3",
|
"node-cron": "3.0.3",
|
||||||
"phin": "^3.7.0",
|
"phin": "^3.7.0",
|
||||||
"prom-client": "15.1.0"
|
"prom-client": "15.1.0",
|
||||||
|
"sharp": "0.33.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"csso": "5.0.5",
|
"csso": "5.0.5",
|
||||||
"sass": "1.66.1",
|
"sass": "1.72.0",
|
||||||
"uglify-js": "3.17.4"
|
"uglify-js": "3.17.4"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,4 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
printf "GIT_TOKEN=$GITEA_TOKEN\n" > ~/.config/artools/artools-pkg.conf
|
|
||||||
printf "ARTIX_MIRROR=$ARTIX_MIRROR\nARCH_MIRROR=$ARCH_MIRROR\nARTIX_REPOS=$ARTIX_REPOS\nARCH_REPOS=$ARCH_REPOS" "%s" "%s" > ~/.config/artix-checkupdates/config && \
|
|
||||||
node index.js
|
|
@@ -97,6 +97,10 @@ header {
|
|||||||
a:hover,
|
a:hover,
|
||||||
a:focus {
|
a:focus {
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
|
|
||||||
|
&.logo svg .artix-logo-base {
|
||||||
|
fill: #53bffc;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
a.logo {
|
a.logo {
|
||||||
@@ -137,6 +141,15 @@ header {
|
|||||||
|
|
||||||
footer {
|
footer {
|
||||||
font-size: 9pt;
|
font-size: 9pt;
|
||||||
|
|
||||||
|
ul li {
|
||||||
|
display: inline-block;
|
||||||
|
padding: 0 1em 0 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
table tr td:last-child {
|
||||||
|
min-width: 6em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.container {
|
.container {
|
||||||
@@ -167,6 +180,10 @@ footer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@media screen and (max-width:270px) {
|
@media screen and (max-width:270px) {
|
||||||
|
footer ul li {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
header nav ul li {
|
header nav ul li {
|
||||||
display: block;
|
display: block;
|
||||||
|
|
||||||
@@ -174,4 +191,10 @@ footer {
|
|||||||
display: block;
|
display: block;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
html,
|
||||||
|
body {
|
||||||
|
font-size: 1em;
|
||||||
|
line-height: 1.1em;
|
||||||
|
}
|
||||||
}
|
}
|
BIN
userbar/userbar.png
Normal file
BIN
userbar/userbar.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 11 KiB |
BIN
userbar/userbar.psd
Normal file
BIN
userbar/userbar.psd
Normal file
Binary file not shown.
86
userbar/visitor/visitor.txt
Normal file
86
userbar/visitor/visitor.txt
Normal 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]
|
BIN
userbar/visitor/visitor1.ttf
Normal file
BIN
userbar/visitor/visitor1.ttf
Normal file
Binary file not shown.
BIN
userbar/visitor/visitor2.ttf
Normal file
BIN
userbar/visitor/visitor2.ttf
Normal file
Binary file not shown.
@@ -1,5 +1,9 @@
|
|||||||
<div class="container bg">
|
<div class="container bg">
|
||||||
<footer>
|
<footer>
|
||||||
© <%= (new Date()).getFullYear() %> Artix Linux
|
<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>
|
||||||
|
</ul>
|
||||||
</footer>
|
</footer>
|
||||||
</div>
|
</div>
|
@@ -9,6 +9,6 @@
|
|||||||
<meta name="apple-mobile-web-app-title" content="Artix Checkupdates">
|
<meta name="apple-mobile-web-app-title" content="Artix Checkupdates">
|
||||||
<meta name="application-name" content="Artix Checkupdates">
|
<meta name="application-name" content="Artix Checkupdates">
|
||||||
<meta name="theme-color" content="#212121">
|
<meta name="theme-color" content="#212121">
|
||||||
<link rel="stylesheet" href="/assets/css/styles.css?v=1">
|
<link rel="stylesheet" href="/assets/css/styles.css?v=2">
|
||||||
<link rel="shortcut icon" href="/assets/svg/artix_logo.svg">
|
<link rel="shortcut icon" href="/assets/svg/artix_logo.svg">
|
||||||
</head>
|
</head>
|
@@ -9,7 +9,7 @@
|
|||||||
<li><a href="https://artixlinux.org/">Artix Linux</a></li>
|
<li><a href="https://artixlinux.org/">Artix Linux</a></li>
|
||||||
<li><a href="https://forum.artixlinux.org/">Forum</a></li>
|
<li><a href="https://forum.artixlinux.org/">Forum</a></li>
|
||||||
<li><a href="https://wiki.artixlinux.org/">Wiki</a></li>
|
<li><a href="https://wiki.artixlinux.org/">Wiki</a></li>
|
||||||
<li><a href="https://gitea.artixlinux.org/">Sources</a></li>
|
<li><a href="https://gitea.artixlinux.org/explore/repos">Sources</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</nav>
|
</nav>
|
||||||
</header>
|
</header>
|
||||||
|
@@ -9,6 +9,7 @@
|
|||||||
<% maintainers && maintainers.forEach(m => { %>
|
<% maintainers && maintainers.forEach(m => { %>
|
||||||
<li><a href="/maintainer/<%= m %>"><%= m %></a></li>
|
<li><a href="/maintainer/<%= m %>"><%= m %></a></li>
|
||||||
<% }); %>
|
<% }); %>
|
||||||
|
<li><a href="/maintainer/orphan">Orphan Packages</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
<h2>All Pending</h2>
|
<h2>All Pending</h2>
|
||||||
<table>
|
<table>
|
||||||
@@ -16,16 +17,10 @@
|
|||||||
<th>Package</th>
|
<th>Package</th>
|
||||||
<th>Action</th>
|
<th>Action</th>
|
||||||
</tr>
|
</tr>
|
||||||
<% savedata.move && savedata.move.forEach(p => { %>
|
<% packages && packages.forEach(p => { %>
|
||||||
<tr>
|
<tr>
|
||||||
<td><%= p %></td>
|
<td><a href="<%= p.url %>"><%= p.package %></a></td>
|
||||||
<td>Move</td>
|
<td><%= p.action %></td>
|
||||||
</tr>
|
|
||||||
<% }); %>
|
|
||||||
<% savedata.update && savedata.update.forEach(p => { %>
|
|
||||||
<tr>
|
|
||||||
<td><%= p %></td>
|
|
||||||
<td>Update</td>
|
|
||||||
</tr>
|
</tr>
|
||||||
<% }); %>
|
<% }); %>
|
||||||
</table>
|
</table>
|
||||||
|
@@ -3,25 +3,26 @@
|
|||||||
<body>
|
<body>
|
||||||
<%- include("header", locals) %>
|
<%- include("header", locals) %>
|
||||||
<div class="container bg">
|
<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>
|
<h1><%= maintainer %>'s Operations</h1>
|
||||||
<p>
|
<p>
|
||||||
<%= maintainer %> owns <a href="https://gitea.artixlinux.org/explore/repos?q=maintainer-<%= maintainer %>&topic=1"><%= packagesOwned %> packages</a>.
|
<%= maintainer %> owns <a href="https://gitea.artixlinux.org/explore/repos?q=maintainer-<%= maintainer %>&topic=1"><%= packagesOwned %> packages</a>.
|
||||||
</p>
|
</p>
|
||||||
|
<% } %>
|
||||||
<table>
|
<table>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Package</th>
|
<th>Package</th>
|
||||||
<th>Action</th>
|
<th>Action</th>
|
||||||
</tr>
|
</tr>
|
||||||
<% moves && moves.forEach(p => { %>
|
<% packages && packages.forEach(p => { %>
|
||||||
<tr>
|
<tr>
|
||||||
<td><%= p.package %></td>
|
<td><a href="<%= p.url %>"><%= p.package.package %></a></td>
|
||||||
<td>Move</td>
|
<td><%= p.action %></td>
|
||||||
</tr>
|
|
||||||
<% }); %>
|
|
||||||
<% updates && updates.forEach(p => { %>
|
|
||||||
<tr>
|
|
||||||
<td><%= p.package %></td>
|
|
||||||
<td>Update</td>
|
|
||||||
</tr>
|
</tr>
|
||||||
<% }); %>
|
<% }); %>
|
||||||
</table>
|
</table>
|
||||||
|
148
web.js
148
web.js
@@ -1,5 +1,6 @@
|
|||||||
const express = require('express');
|
const express = require('express');
|
||||||
const prom = require('prom-client');
|
const prom = require('prom-client');
|
||||||
|
const sharp = require('sharp');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
@@ -7,23 +8,104 @@ const PROJECT_ROOT = __dirname;
|
|||||||
const VIEWOPTIONS = {
|
const VIEWOPTIONS = {
|
||||||
outputFunctionName: 'echo'
|
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) {
|
function inliner(file) {
|
||||||
return fs.readFileSync(path.join(PROJECT_ROOT, 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)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function createOutlinedText(string, meta, gravity = 'west') {
|
||||||
|
const txt = sharp({
|
||||||
|
create: {
|
||||||
|
width: meta.width,
|
||||||
|
height: meta.height,
|
||||||
|
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,
|
||||||
|
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 {
|
class Web {
|
||||||
constructor(db, options, savedata) {
|
constructor(db, options, savedata) {
|
||||||
const app = express();
|
const app = express();
|
||||||
const port = process.env.PORT || options.port || 8080;
|
const port = process.env.PORT || options.port || 8080;
|
||||||
const METRICPREFIX = process.env.METRICPREFIX || 'artixpackages_';
|
const METRICPREFIX = process.env.METRICPREFIX || 'artixpackages_';
|
||||||
const maintainers = this._maintainers = options.maintainers.map(m => typeof m === 'object' ? m.name : m).sort();
|
const maintainers = this._maintainers = (options.maintainers || []).map(m => typeof m === 'object' ? m.name : m).sort();
|
||||||
|
|
||||||
app.set('trust proxy', 1);
|
app.set('trust proxy', 1);
|
||||||
app.set('view engine', 'ejs');
|
app.set('view engine', 'ejs');
|
||||||
app.set('view options', VIEWOPTIONS);
|
app.set('view options', VIEWOPTIONS);
|
||||||
|
|
||||||
function sendError(res, status, description) {
|
function sendError(req, res, status, description) {
|
||||||
|
console.log(`${status} (${description}): ${req.url} requested by ${req.ip} "${req.headers['user-agent']}"`);
|
||||||
res.render('error',
|
res.render('error',
|
||||||
{
|
{
|
||||||
inliner,
|
inliner,
|
||||||
@@ -51,6 +133,8 @@ class Web {
|
|||||||
});
|
});
|
||||||
|
|
||||||
app.get('/', async (_, res) => {
|
app.get('/', async (_, res) => {
|
||||||
|
let packages = prepPackages(savedata.move, 'Move');
|
||||||
|
packages = packages.concat(prepPackages(savedata.update, 'Update'));
|
||||||
res.render('index',
|
res.render('index',
|
||||||
{
|
{
|
||||||
inliner,
|
inliner,
|
||||||
@@ -58,7 +142,7 @@ class Web {
|
|||||||
prefix: 'Artix Checkupdates',
|
prefix: 'Artix Checkupdates',
|
||||||
suffix: 'Web Edition'
|
suffix: 'Web Edition'
|
||||||
},
|
},
|
||||||
savedata,
|
packages,
|
||||||
maintainers: maintainers
|
maintainers: maintainers
|
||||||
},
|
},
|
||||||
function (err, html) {
|
function (err, html) {
|
||||||
@@ -67,7 +151,7 @@ class Web {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
sendError(res, 500, 'Something went wrong. Try again later.');
|
sendError(req, res, 500, 'Something went wrong. Try again later.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@@ -76,6 +160,8 @@ class Web {
|
|||||||
app.get('/maintainer/:maintainer', async (req, res) => {
|
app.get('/maintainer/:maintainer', async (req, res) => {
|
||||||
const maintainer = req.params.maintainer;
|
const maintainer = req.params.maintainer;
|
||||||
const packagesOwned = db.getMaintainerPackageCount(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 (packagesOwned > 0) {
|
||||||
res.render('maintainer',
|
res.render('maintainer',
|
||||||
{
|
{
|
||||||
@@ -86,8 +172,7 @@ class Web {
|
|||||||
},
|
},
|
||||||
maintainer,
|
maintainer,
|
||||||
packagesOwned,
|
packagesOwned,
|
||||||
moves: db.getPackagesByMaintainer(maintainer, 'move'),
|
packages
|
||||||
updates: db.getPackagesByMaintainer(maintainer, 'udate'),
|
|
||||||
},
|
},
|
||||||
function (err, html) {
|
function (err, html) {
|
||||||
if (!err) {
|
if (!err) {
|
||||||
@@ -101,7 +186,39 @@ class Web {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
sendError(res, 404, 'File not found');
|
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 = 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');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -109,6 +226,18 @@ class Web {
|
|||||||
res.set('content-type', 'text/plain').send('User-agent: *\nDisallow: /metrics\n');
|
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;
|
||||||
|
if (acceptHeader && acceptHeader.includes('application/json')) {
|
||||||
|
res.json({
|
||||||
|
maintainers
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
res.send(maintainers.join(' '));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
const register = prom.register;
|
const register = prom.register;
|
||||||
|
|
||||||
new prom.Gauge({
|
new prom.Gauge({
|
||||||
@@ -156,7 +285,8 @@ class Web {
|
|||||||
res.end(await register.metrics());
|
res.end(await register.metrics());
|
||||||
}
|
}
|
||||||
catch (ex) {
|
catch (ex) {
|
||||||
res.status(500).send(ex);
|
console.error(err);
|
||||||
|
res.status(500).send('something went wrong.');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -164,6 +294,8 @@ class Web {
|
|||||||
maxAge: '30d'
|
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}`));
|
this._webserver = app.listen(port, () => console.log(`artix-packy-notifier-web running on port ${port}`));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user