Compare commits
13 Commits
1e60fc23ab
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 3f225a1ecb | |||
| bade2f9b86 | |||
| 58460d988d | |||
| 8fb05f2662 | |||
| 2e325fe018 | |||
| 52dbd158a9 | |||
| f897a3e4ce | |||
| bf6fb81a73 | |||
| 7bb2dd5434 | |||
| fa5932d270 | |||
| 09f0d3ce1f | |||
| 6b2f93b962 | |||
| 1b8c9ccaeb |
3
.dockerignore
Normal file
3
.dockerignore
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
.env
|
||||||
|
*/.env
|
||||||
|
*.md
|
||||||
58
.gitea/workflows/01_docker.yaml
Normal file
58
.gitea/workflows/01_docker.yaml
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
# Credits: https://www.vanmeeuwen.dev/blog/automating-docker-builds-with-gitea-actions
|
||||||
|
# https://gitea.com/gitea/runner-images/src/branch/main/.gitea/workflows/release.yaml
|
||||||
|
|
||||||
|
name: Build and push Docker image
|
||||||
|
run-name: Build ${{ github.ref_name }} image
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- "*"
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Set up QEMU
|
||||||
|
uses: docker/setup-qemu-action@v3
|
||||||
|
|
||||||
|
- name: Set up Docker BuildX
|
||||||
|
uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
|
- name: Login to registry
|
||||||
|
uses: docker/login-action@v2
|
||||||
|
with:
|
||||||
|
registry: gitea.7o7.cx
|
||||||
|
username: ${{ secrets.REGISTRY_USER }}
|
||||||
|
password: ${{ secrets.REGISTRY_PASSWORD }}
|
||||||
|
|
||||||
|
- name: Set outputs
|
||||||
|
id: vars
|
||||||
|
env:
|
||||||
|
BRANCH_NAME: ${{ github.ref_name }}
|
||||||
|
run: |
|
||||||
|
#echo branch_name="$BRANCH_NAME" | tee -a $GITHUB_OUTPUT
|
||||||
|
#echo short_hash=$(git rev-parse --short HEAD) | tee -a $GITHUB_OUTPUT
|
||||||
|
echo current_tag=$GITHUB_REF_NAME | tee -a $GITHUB_OUTPUT
|
||||||
|
|
||||||
|
- name: Build and push
|
||||||
|
uses: docker/build-push-action@v6
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
platforms: |
|
||||||
|
linux/amd64
|
||||||
|
linux/arm64
|
||||||
|
pull: true
|
||||||
|
push: true
|
||||||
|
# Change when working on a different branch!
|
||||||
|
tags: |
|
||||||
|
gitea.7o7.cx/kittyteam/kittybe:master-${{ steps.vars.outputs.current_tag }}
|
||||||
|
gitea.7o7.cx/kittyteam/kittybe:latest
|
||||||
|
|
||||||
|
- name: Log out from registry
|
||||||
|
if: always()
|
||||||
|
run: docker logout gitea.7o7.cx
|
||||||
35
.gitea/workflows/02_release.yaml
Normal file
35
.gitea/workflows/02_release.yaml
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
# Credits: # https://gitea.com/gitea/runner-images/src/branch/main/.gitea/workflows/release.yaml
|
||||||
|
name: Release new version
|
||||||
|
run-name: Release ${{ github.ref_name }}
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- "*"
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
release:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container: docker.io/thegeeklab/git-sv:2.0.9
|
||||||
|
steps:
|
||||||
|
- name: Install tools
|
||||||
|
run: |
|
||||||
|
apk add -q --update --no-cache nodejs
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v6
|
||||||
|
with:
|
||||||
|
fetch-tags: true
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- name: Create changelog
|
||||||
|
run: |
|
||||||
|
git sv current-version
|
||||||
|
git sv release-notes -t ${GITHUB_REF#refs/tags/} -o CHANGELOG.md
|
||||||
|
sed -i '1,2d' CHANGELOG.md # remove version
|
||||||
|
cat CHANGELOG.md
|
||||||
|
|
||||||
|
- name: Release
|
||||||
|
uses: https://github.com/akkuman/gitea-release-action@v1
|
||||||
|
with:
|
||||||
|
body_path: CHANGELOG.md
|
||||||
|
token: "${{ secrets.REPO_RW_TOKEN }}"
|
||||||
37
.gitea/workflows/99_changelog.yaml
Normal file
37
.gitea/workflows/99_changelog.yaml
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
# Credit: https://gitea.com/gitea/helm-gitea/src/branch/main/.gitea/workflows/changelog.yml
|
||||||
|
name: Update changelog
|
||||||
|
run-name: Update changelog on push
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
tags:
|
||||||
|
- "*"
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
changelog:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container: docker.io/thegeeklab/git-sv:2.0.9
|
||||||
|
steps:
|
||||||
|
- name: Install tools
|
||||||
|
run: |
|
||||||
|
apk add -q --update --no-cache nodejs curl jq sed
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v6
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
- name: Generate upcoming changelog
|
||||||
|
run: |
|
||||||
|
git sv rn -o changelog.md
|
||||||
|
export RELEASE_NOTES=$(cat changelog.md)
|
||||||
|
export ISSUE_NUMBER=$(curl -s -H 'Authorization: token ${{ secrets.ISSUE_RW_TOKEN }}' "https://gitea.7o7.cx/api/v1/repos/kittyteam/kittyBE/issues?state=open&q=Changelog%20for%20upcoming%20version" | jq '.[].number')
|
||||||
|
|
||||||
|
echo $RELEASE_NOTES
|
||||||
|
JSON_DATA=$(echo "" | jq -Rs --arg title 'Changelog for upcoming version' --arg body "$(cat changelog.md)" '{title: $title, body: $body}')
|
||||||
|
|
||||||
|
if [ -z "$ISSUE_NUMBER" ]; then
|
||||||
|
curl -s -X POST "https://gitea.7o7.cx/api/v1/repos/kittyteam/kittyBE/issues" -H "Authorization: token ${{ secrets.ISSUE_RW_TOKEN }}" -H "Content-Type: application/json" -d "$JSON_DATA" > /dev/null
|
||||||
|
else
|
||||||
|
curl -s -X PATCH "https://gitea.7o7.cx/api/v1/repos/kittyteam/kittyBE/issues/$ISSUE_NUMBER" -H "Authorization: token ${{ secrets.ISSUE_RW_TOKEN }}" -H "Content-Type: application/json" -d "$JSON_DATA" > /dev/null
|
||||||
|
fi
|
||||||
19
Dockerfile
Normal file
19
Dockerfile
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
# Credit: https://www.digitalocean.com/community/tutorials/how-to-build-a-node-js-application-with-docker
|
||||||
|
|
||||||
|
FROM node:24-trixie-slim AS builder
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
COPY package*.json ./
|
||||||
|
RUN npm ci --only=production && npm cache clean --force
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
FROM node:24-trixie-slim AS production
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
RUN addgroup --gid 1001 nodejs && \
|
||||||
|
adduser --gid 1001 --uid 1001 nodejs
|
||||||
|
COPY --from=builder --chown=nodejs:nodejs /app /app
|
||||||
|
USER nodejs
|
||||||
|
EXPOSE 6567
|
||||||
|
|
||||||
|
CMD ["npm", "run", "server"]
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
# This file will likely be moved into the main repo soon.
|
|
||||||
services:
|
|
||||||
|
|
||||||
postgres:
|
|
||||||
image: "postgres:17.2"
|
|
||||||
ports:
|
|
||||||
- "5432:5432"
|
|
||||||
environment:
|
|
||||||
POSTGRES_USER: "kitty"
|
|
||||||
POSTGRES_PASSWORD: "CHANGEME"
|
|
||||||
POSTGRES_DB: "kittyurl"
|
|
||||||
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import { MigrationInterface, QueryRunner } from "typeorm";
|
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||||
|
|
||||||
export class InitialMigration1764549652720 implements MigrationInterface {
|
export class RevisedMigration1765488793696 implements MigrationInterface {
|
||||||
name = 'InitialMigration1764549652720'
|
name = 'RevisedMigration1765488793696'
|
||||||
|
|
||||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||||
await queryRunner.query(`
|
await queryRunner.query(`
|
||||||
@@ -10,9 +10,10 @@ export class InitialMigration1764549652720 implements MigrationInterface {
|
|||||||
"subdomain" character varying,
|
"subdomain" character varying,
|
||||||
"shortUri" character varying NOT NULL,
|
"shortUri" character varying NOT NULL,
|
||||||
"fullUrl" character varying NOT NULL,
|
"fullUrl" character varying NOT NULL,
|
||||||
"role" character varying NOT NULL,
|
|
||||||
"createDate" bigint NOT NULL,
|
"createDate" bigint NOT NULL,
|
||||||
"expiryDate" bigint NOT NULL,
|
"expiryDate" bigint,
|
||||||
|
"visits" bigint NOT NULL,
|
||||||
|
"privacy" boolean NOT NULL,
|
||||||
"authorId" integer,
|
"authorId" integer,
|
||||||
CONSTRAINT "PK_ecf17f4a741d3c5ba0b4c5ab4b6" PRIMARY KEY ("id")
|
CONSTRAINT "PK_ecf17f4a741d3c5ba0b4c5ab4b6" PRIMARY KEY ("id")
|
||||||
)
|
)
|
||||||
@@ -22,7 +23,7 @@ export class InitialMigration1764549652720 implements MigrationInterface {
|
|||||||
"id" SERIAL NOT NULL,
|
"id" SERIAL NOT NULL,
|
||||||
"name" character varying NOT NULL,
|
"name" character varying NOT NULL,
|
||||||
"passwordHash" character varying NOT NULL,
|
"passwordHash" character varying NOT NULL,
|
||||||
"role" character varying NOT NULL,
|
"role" integer NOT NULL,
|
||||||
"createdAt" bigint NOT NULL,
|
"createdAt" bigint NOT NULL,
|
||||||
CONSTRAINT "UQ_51b8b26ac168fbe7d6f5653e6cf" UNIQUE ("name"),
|
CONSTRAINT "UQ_51b8b26ac168fbe7d6f5653e6cf" UNIQUE ("name"),
|
||||||
CONSTRAINT "PK_a3ffb1c0c8416b9fc6f907b7433" PRIMARY KEY ("id")
|
CONSTRAINT "PK_a3ffb1c0c8416b9fc6f907b7433" PRIMARY KEY ("id")
|
||||||
17
src/app.ts
17
src/app.ts
@@ -1,5 +1,7 @@
|
|||||||
import * as express from 'express';
|
import * as express from 'express';
|
||||||
import router from './routes';
|
import router from './routes';
|
||||||
|
import * as dotenv from "dotenv";
|
||||||
|
dotenv.config({ quiet: true });
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
|
|
||||||
@@ -20,6 +22,21 @@ const swaggerSpec = swaggerJsdoc(swaggerJsdocOpts);
|
|||||||
|
|
||||||
app.use(express.json());
|
app.use(express.json());
|
||||||
app.use(router);
|
app.use(router);
|
||||||
|
if (process.env.DEBUG === "true") {
|
||||||
app.use('/swagger', swaggerUi.serve, swaggerUi.setup(swaggerSpec));
|
app.use('/swagger', swaggerUi.serve, swaggerUi.setup(swaggerSpec));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle 404s
|
||||||
|
// https://stackoverflow.com/a/9802006
|
||||||
|
app.use(function(req, res) {
|
||||||
|
res.status(404);
|
||||||
|
|
||||||
|
if (req.accepts('json')) {
|
||||||
|
res.json({ status: 'error', error: 'Not found' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
res.type('txt').send('Not found');
|
||||||
|
});
|
||||||
app.listen(6567, () => console.log('(HTTP Server) Listening on port 6567.'));
|
app.listen(6567, () => console.log('(HTTP Server) Listening on port 6567.'));
|
||||||
|
|
||||||
|
|||||||
@@ -4,28 +4,45 @@ import { User } from "./User"
|
|||||||
@Entity("links")
|
@Entity("links")
|
||||||
export class Link {
|
export class Link {
|
||||||
|
|
||||||
|
// Unique link id.
|
||||||
@PrimaryGeneratedColumn()
|
@PrimaryGeneratedColumn()
|
||||||
id: number
|
id: number
|
||||||
|
|
||||||
|
// Experimental: subdomain which should be a part of the short url.
|
||||||
|
// For instance in the URL "abc.example.com/def", abc is the subdomain.
|
||||||
|
// "def.example.com/def" won't resolve to the URL that "abc.example.com/def" does.
|
||||||
@Column({ nullable: true })
|
@Column({ nullable: true })
|
||||||
subdomain: string
|
subdomain: string | null
|
||||||
|
|
||||||
|
// Shortened Uri.
|
||||||
@Column()
|
@Column()
|
||||||
shortUri: string
|
shortUri: string
|
||||||
|
|
||||||
|
// URL to which the user should be redirected
|
||||||
@Column()
|
@Column()
|
||||||
fullUrl: string
|
fullUrl: string
|
||||||
|
|
||||||
@Column()
|
// Unix timestamp of link creation date.
|
||||||
role: string
|
|
||||||
|
|
||||||
@Column('bigint')
|
@Column('bigint')
|
||||||
createDate: number
|
createDate: number
|
||||||
|
|
||||||
@Column('bigint')
|
// Unix timestamp of when the link should expire.
|
||||||
expiryDate: number
|
// If null, the link will never expire unless deleted.
|
||||||
|
@Column('bigint', { nullable: true })
|
||||||
|
expiryDate: number | null
|
||||||
|
|
||||||
@ManyToOne(() => User, (user) => user.links)
|
// Aggregated amount of visits.
|
||||||
|
@Column('bigint')
|
||||||
|
visits: number
|
||||||
|
|
||||||
|
// Link privacy:
|
||||||
|
// - true, if link is private
|
||||||
|
// - false, if link can be shown in a list of recent links publicly.
|
||||||
|
@Column()
|
||||||
|
privacy: boolean
|
||||||
|
|
||||||
|
// User to which the shortened URL belongs.
|
||||||
|
@ManyToOne(() => User, (user) => user.links, { nullable: true })
|
||||||
@JoinTable()
|
@JoinTable()
|
||||||
author: User
|
author: User | null
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,21 +4,29 @@ import { Link } from "./Link"
|
|||||||
@Entity("users")
|
@Entity("users")
|
||||||
export class User {
|
export class User {
|
||||||
|
|
||||||
|
// Unique user id.
|
||||||
@PrimaryGeneratedColumn()
|
@PrimaryGeneratedColumn()
|
||||||
id: number
|
id: number
|
||||||
|
|
||||||
|
// User name, must be unique.
|
||||||
@Column({ unique: true })
|
@Column({ unique: true })
|
||||||
name: string
|
name: string
|
||||||
|
|
||||||
|
// Salted password hash.
|
||||||
@Column()
|
@Column()
|
||||||
passwordHash: string
|
passwordHash: string
|
||||||
|
|
||||||
|
// User role:
|
||||||
|
// - 0 - means unprivileged user,
|
||||||
|
// - 1 - means administrative user.
|
||||||
@Column()
|
@Column()
|
||||||
role: string
|
role: number
|
||||||
|
|
||||||
|
// Account creation date as a Unix timestamp.
|
||||||
@Column('bigint')
|
@Column('bigint')
|
||||||
createdAt: number
|
createdAt: number
|
||||||
|
|
||||||
|
// List of shortened URLs which belong to the user.
|
||||||
@OneToMany(() => Link, (link) => link.author)
|
@OneToMany(() => Link, (link) => link.author)
|
||||||
links: Link[];
|
links: Link[];
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user