From b20bbf40fc348808f8298ecb3ab96302348aac76 Mon Sep 17 00:00:00 2001 From: Cory Sanin Date: Tue, 23 Sep 2025 16:09:31 -0500 Subject: [PATCH] Track and display build authors --- scripts/build.js | 10 +--------- src/DB.ts | 37 ++++++++++++++++++++++++++++--------- src/Web.ts | 7 ++++--- views/build.ejs | 9 +++++++-- views/index.ejs | 2 +- 5 files changed, 41 insertions(+), 24 deletions(-) diff --git a/scripts/build.js b/scripts/build.js index 2d7ca4b..42dc403 100644 --- a/scripts/build.js +++ b/scripts/build.js @@ -4,14 +4,6 @@ document.addEventListener('DOMContentLoaded', function () { const buildStatusTxt = this.getElementById('buildStatus'); let started = logContainer.childElementCount > 0; - /** - * Get the correct path to establish a ws connection - * @param {Location} loc - */ - function wsPath(loc) { - return loc.pathname.replace(/\/$/, '') + '/ws'; - } - /** * Add log line to the DOM * @param {string[]} str @@ -52,7 +44,7 @@ document.addEventListener('DOMContentLoaded', function () { const loc = window.location; let new_uri = loc.protocol === 'https:' ? 'wss:' : 'ws:'; new_uri += "//" + loc.host; - new_uri += wsPath(loc); + new_uri += loc.pathname + 'ws'; var ws = new WebSocket(new_uri); ws.onmessage = function (message) { diff --git a/src/DB.ts b/src/DB.ts index 534dd47..53dff70 100644 --- a/src/DB.ts +++ b/src/DB.ts @@ -149,13 +149,24 @@ class DB { } }); + this.build.belongsTo(this.user); + this.user.hasMany(this.build); + this.sync(); } private async sync(): Promise { + await this.user.sync(); await this.build.sync(); await this.logChunk.sync(); - await this.user.sync(); + + if (!(await this.getUser('-1'))) { + await this.createUser({ + id: '-1', + username: '???', + displayName: 'Anonymous User' + }); + } } public async getUser(id: string): Promise { @@ -171,13 +182,14 @@ class DB { return user.id; } - public async createBuild(repo: string, commit: string, patch: string, distro: string, dependencies: string): Promise { + public async createBuild(repo: string, commit: string, patch: string, distro: string, dependencies: string, author: string): Promise { const buildRec = await this.build.create({ repo, commit: commit || null, patch: patch || null, distro, - dependencies + dependencies, + userId: author || '-1' }); return buildRec.id; } @@ -224,14 +236,17 @@ class DB { } public async getBuild(id: number): Promise { - return await this.build.findByPk(id); + return await this.build.findByPk(id, { + include: this.user + }); } public async getBuilds(): Promise { return await this.build.findAll({ attributes: SELECT, order: [['id', 'DESC']], - where: FRESH + where: FRESH, + include: this.user }); } @@ -242,7 +257,8 @@ class DB { where: { ...FRESH, status - } + }, + include: this.user }); } @@ -253,7 +269,8 @@ class DB { where: { ...FRESH, distro - } + }, + include: this.user }); } @@ -264,7 +281,8 @@ class DB { where: { ...FRESH, ...filterable - } + }, + include: this.user }); } @@ -287,7 +305,8 @@ class DB { { repo: { [Op.iLike]: `%${query}%` } } ] }, - limit: 100 + limit: 100, + include: this.user }); } diff --git a/src/Web.ts b/src/Web.ts index 2f9147d..8c1a1c6 100644 --- a/src/Web.ts +++ b/src/Web.ts @@ -215,13 +215,14 @@ class Web { req.body.commit || null, req.body.patch || null, req.body.distro || 'arch', - req.body.dependencies || 'stable' + req.body.dependencies || 'stable', + req?.user?.['id'] ); - res.redirect(`/build/${sqids.encode([buildId])}`); + res.redirect(`/build/${sqids.encode([buildId])}/`); this.buildController.triggerBuild(); }); - app.get('/build/:id{/}', async (req, res) => { + app.get('/build/:id/', async (req, res) => { const build = await this.db.getBuild(sqids.decode(req.params.id)?.[0]); showBuild(req, res, build); }); diff --git a/views/build.ejs b/views/build.ejs index 0926315..cd7e96d 100644 --- a/views/build.ejs +++ b/views/build.ejs @@ -18,17 +18,22 @@ <%= build.distro %> <%= build.dependencies %> <%= build.startTime %> + <% if (build.userId !== '-1') { %> + <%= build.user.displayName %> (<%= build.user.username %>) + <% } %> + <% if (build.sqid) { %> + <% } %> <% if (!ended) { %> <% } %> -

Full logs

+

Full logs

<% (log || []).forEach(line => { %>

<%= line %>

<% }) %>
<% if (!ended) { %> diff --git a/views/index.ejs b/views/index.ejs index 968f361..3993acf 100644 --- a/views/index.ejs +++ b/views/index.ejs @@ -20,7 +20,7 @@ <% builds.forEach(build => { %> - <%= build.repo %> + <%= build.repo %> <%= build.distro %> <%= build.startTime %> <%= timeElapsed(build.startTime, build.endTime) %>