chore: restart the repository with a clean history
CI / Docker image (push) Successful in 12s
CI / Server (push) Successful in 25s
CI / CLI (push) Successful in 13s
Development image / Development image (push) Successful in 21s
CI / CLI (windows) (push) Successful in 57s
CI / CLI (linux-arm64, static) (push) Successful in 1m37s
Release / Prepare release (push) Successful in 2s
Release / Server (linux-x64) (push) Successful in 53s
Release / CLI (linux-arm64, static) (push) Successful in 1m32s
Release / Docker image (push) Successful in 2m48s
Release / Server (windows-x64) (push) Successful in 6m20s
Release / CLI (windows-x64) (push) Successful in 6m48s
Release / CLI (linux-x64) (push) Successful in 7m8s
Release / Publish release (push) Successful in 1s
CI / Docker image (push) Successful in 12s
CI / Server (push) Successful in 25s
CI / CLI (push) Successful in 13s
Development image / Development image (push) Successful in 21s
CI / CLI (windows) (push) Successful in 57s
CI / CLI (linux-arm64, static) (push) Successful in 1m37s
Release / Prepare release (push) Successful in 2s
Release / Server (linux-x64) (push) Successful in 53s
Release / CLI (linux-arm64, static) (push) Successful in 1m32s
Release / Docker image (push) Successful in 2m48s
Release / Server (windows-x64) (push) Successful in 6m20s
Release / CLI (windows-x64) (push) Successful in 6m48s
Release / CLI (linux-x64) (push) Successful in 7m8s
Release / Publish release (push) Successful in 1s
Squash the tree into one commit, drop docs/architecture.html, reset the version line to 0.3.0, consolidate the changelog, enable Renovate automerge for non-major updates and add AGENTS.md.
This commit is contained in:
438 files changed
+45070
No files matched your search
@@ -0,0 +1,49 @@
|
||||
const Invite = require("../models/Invite");
|
||||
const Account = require("../models/Account");
|
||||
const { hashToken, randomToken } = require("../utils/ids");
|
||||
const logger = require("../utils/logger");
|
||||
|
||||
const describe = (invite, owner) => ({
|
||||
id: invite.id,
|
||||
label: invite.label,
|
||||
owner: owner || null,
|
||||
createdAt: invite.createdAt,
|
||||
lastUsedAt: invite.lastUsedAt,
|
||||
uses: invite.uses,
|
||||
});
|
||||
|
||||
const linkFor = (publicUrl, token) => `${publicUrl}/@frislit/invite/${token}`;
|
||||
|
||||
const create = async (accountId, label) => {
|
||||
const name = String(label || "").trim();
|
||||
if (!name) return { code: 400, message: "Give the invite a label" };
|
||||
const token = randomToken(48);
|
||||
const invite = await Invite.create({ accountId, label: name, tokenHash: hashToken(token) });
|
||||
logger.info(`Invite "${name}" created`, { id: invite.id });
|
||||
return { invite: describe(invite), token };
|
||||
};
|
||||
|
||||
const list = async accountId => {
|
||||
const where = accountId === undefined ? {} : { accountId };
|
||||
const invites = await Invite.findAll({ where, order: [["createdAt", "DESC"]] });
|
||||
if (accountId !== undefined) return invites.map(invite => describe(invite));
|
||||
const names = new Map((await Account.findAll()).map(account => [account.id, account.username]));
|
||||
return invites.map(invite => describe(invite, names.get(invite.accountId)));
|
||||
};
|
||||
|
||||
const revoke = async (id, accountId) => {
|
||||
const where = accountId === undefined ? { id } : { id, accountId };
|
||||
const invite = await Invite.findOne({ where });
|
||||
if (!invite) return { code: 404, message: "Invite not found" };
|
||||
await Invite.destroy({ where: { id: invite.id } });
|
||||
logger.info(`Invite "${invite.label}" revoked`, { id });
|
||||
return { message: `${invite.label} revoked` };
|
||||
};
|
||||
|
||||
const verify = token => (typeof token === "string" && token ? Invite.findOne({ where: { tokenHash: hashToken(token) } }) : null);
|
||||
|
||||
const used = async invite => {
|
||||
await Invite.update({ lastUsedAt: new Date(), uses: invite.uses + 1 }, { where: { id: invite.id } });
|
||||
};
|
||||
|
||||
module.exports = { create, list, revoke, verify, used, linkFor };
|
||||
Reference in new issue
Block a user