From d559d1a03668acf277b1d5d263bf7366543f18b6 Mon Sep 17 00:00:00 2001 From: sam Date: Tue, 26 Dec 2023 01:34:50 +0100 Subject: [PATCH 01/14] chore: upgrade sveltekit to 2.0.0, upgrade svelte to 4.0.0 --- frontend/package.json | 27 +- frontend/src/app.d.ts | 6 +- frontend/src/lib/components/ActiveLink.svelte | 2 +- frontend/src/lib/components/ErrorAlert.svelte | 2 +- frontend/src/lib/components/IconButton.svelte | 2 +- .../lib/components/PartialMemberCard.svelte | 2 +- frontend/src/lib/components/StatusIcon.svelte | 2 +- frontend/src/lib/components/Toast.svelte | 2 +- .../lib/components/edit/EditableField.svelte | 2 +- .../lib/components/edit/EditableName.svelte | 2 +- .../components/edit/EditablePronouns.svelte | 2 +- .../src/lib/components/edit/FieldEntry.svelte | 2 +- .../src/lib/components/edit/FlagButton.svelte | 2 +- .../lib/components/edit/MarkdownHelp.svelte | 2 +- frontend/src/routes/+layout.svelte | 2 +- frontend/src/routes/+page.svelte | 2 +- .../src/routes/@[username]/+page.server.ts | 2 +- frontend/src/routes/@[username]/+page.svelte | 2 +- .../src/routes/@[username]/ProfileFlag.svelte | 2 +- .../src/routes/@[username]/ProfileLink.svelte | 2 +- .../routes/@[username]/ReportButton.svelte | 2 +- .../@[username]/[memberName]/+page.server.ts | 4 +- .../@[username]/[memberName]/+page.svelte | 2 +- .../[memberName]/edit/+layout.svelte | 2 +- .../@[username]/[memberName]/edit/+layout.ts | 4 +- .../[memberName]/edit/+page.svelte | 2 +- .../[memberName]/edit/bio/+page.svelte | 2 +- .../[memberName]/edit/fields/+page.svelte | 2 +- .../[memberName]/edit/flags/+page.svelte | 2 +- .../[memberName]/edit/other/+page.svelte | 2 +- .../[memberName]/edit/pronouns/+page.svelte | 2 +- .../routes/@[username]/badges/Admin.svelte | 2 +- .../routes/@[username]/edit/+layout.svelte | 2 +- .../src/routes/@[username]/edit/+layout.ts | 4 +- .../src/routes/@[username]/edit/+page.svelte | 2 +- .../routes/@[username]/edit/bio/+page.svelte | 2 +- .../@[username]/edit/fields/+page.svelte | 2 +- .../@[username]/edit/flags/+page.svelte | 2 +- .../@[username]/edit/other/+page.svelte | 2 +- .../edit/other/CustomPreference.svelte | 2 +- .../@[username]/edit/other/IconPicker.svelte | 2 +- .../@[username]/edit/pronouns/+page.svelte | 2 +- .../src/routes/[username]/+page.server.ts | 4 +- frontend/src/routes/auth/login/+page.svelte | 2 +- .../src/routes/auth/login/CallbackPage.svelte | 2 +- frontend/src/routes/edit/member/[id]/+page.ts | 4 +- frontend/src/routes/edit/profile/+page.ts | 4 +- frontend/src/routes/nav/Navigation.svelte | 2 +- .../routes/pronouns/[...pronouns]/+page.ts | 4 +- frontend/src/routes/reports/+page.svelte | 2 +- frontend/src/routes/reports/ReportCard.svelte | 2 +- frontend/src/routes/settings/+layout.svelte | 2 +- frontend/src/routes/settings/+layout.ts | 2 +- frontend/src/routes/settings/+page.svelte | 2 +- .../src/routes/settings/auth/+page.svelte | 2 +- .../src/routes/settings/export/+page.svelte | 2 +- frontend/src/routes/settings/export/+page.ts | 2 +- .../src/routes/settings/flags/+page.svelte | 2 +- .../src/routes/settings/flags/Flag.svelte | 2 +- .../src/routes/settings/invites/+page.svelte | 2 +- .../src/routes/settings/members/+page.svelte | 2 +- .../src/routes/settings/tokens/+page.svelte | 2 +- .../src/routes/settings/warnings/+page.svelte | 2 +- frontend/svelte.config.js | 2 +- pnpm-lock.yaml | 1645 ++++++++++++++--- 65 files changed, 1441 insertions(+), 375 deletions(-) diff --git a/frontend/package.json b/frontend/package.json index a460457..1628226 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -12,11 +12,13 @@ "format": "prettier --plugin-search-dir . --write ." }, "devDependencies": { - "@sveltejs/adapter-auto": "^2.0.0", - "@sveltejs/adapter-node": "^1.2.3", - "@sveltejs/kit": "^1.15.0", - "@types/luxon": "^3.2.2", - "@types/markdown-it": "^12.2.3", + "@sveltejs/adapter-auto": "^3.0.0", + "@sveltejs/adapter-node": "^2.0.0", + "@sveltejs/kit": "^2.0.0", + "@sveltejs/vite-plugin-svelte": "^3.0.0", + "@sveltestrap/sveltestrap": "^6.0.5", + "@types/luxon": "^3.3.7", + "@types/markdown-it": "^13.0.7", "@types/node": "^18.15.11", "@types/sanitize-html": "^2.9.0", "@typescript-eslint/eslint-plugin": "^5.57.1", @@ -25,14 +27,13 @@ "eslint-config-prettier": "^8.8.0", "eslint-plugin-svelte3": "^4.0.0", "prettier": "^2.8.7", - "prettier-plugin-svelte": "^2.10.0", - "svelte": "^3.58.0", - "svelte-check": "^3.1.4", + "prettier-plugin-svelte": "^2.10.1", + "svelte": "^4.0.0", + "svelte-check": "^3.4.3", "svelte-hcaptcha": "^0.1.1", - "sveltestrap": "^5.10.0", "tslib": "^2.5.0", - "typescript": "^4.9.5", - "vite": "^4.2.1", + "typescript": "^5.0.0", + "vite": "^5.0.0", "vite-plugin-markdown": "^2.1.0" }, "type": "module", @@ -41,8 +42,8 @@ "@popperjs/core": "^2.11.7", "@sentry/node": "^7.46.0", "base64-arraybuffer": "^1.0.2", - "bootstrap": "5.3.0-alpha1", - "bootstrap-icons": "^1.10.4", + "bootstrap": "^5.3.2", + "bootstrap-icons": "^1.11.2", "jose": "^4.13.1", "luxon": "^3.3.0", "markdown-it": "^13.0.1", diff --git a/frontend/src/app.d.ts b/frontend/src/app.d.ts index d4759fd..ba59572 100644 --- a/frontend/src/app.d.ts +++ b/frontend/src/app.d.ts @@ -1,15 +1,15 @@ // See https://kit.svelte.dev/docs/types#app -import type { ErrorCode } from "$lib/api/entities"; +import type { APIError, ErrorCode } from "$lib/api/entities"; // for information about these interfaces declare global { namespace App { - interface Error { + type Error = { code: ErrorCode; message?: string | undefined; details?: string | undefined; - } + } | APIError // interface Locals {} // interface PageData {} // interface Platform {} diff --git a/frontend/src/lib/components/ActiveLink.svelte b/frontend/src/lib/components/ActiveLink.svelte index d9bc887..969cfbd 100644 --- a/frontend/src/lib/components/ActiveLink.svelte +++ b/frontend/src/lib/components/ActiveLink.svelte @@ -1,5 +1,5 @@ diff --git a/frontend/src/lib/components/IconButton.svelte b/frontend/src/lib/components/IconButton.svelte index c131a4d..240339a 100644 --- a/frontend/src/lib/components/IconButton.svelte +++ b/frontend/src/lib/components/IconButton.svelte @@ -1,5 +1,5 @@ diff --git a/frontend/src/routes/@[username]/+page.server.ts b/frontend/src/routes/@[username]/+page.server.ts index 447c5e3..1e7b8af 100644 --- a/frontend/src/routes/@[username]/+page.server.ts +++ b/frontend/src/routes/@[username]/+page.server.ts @@ -11,7 +11,7 @@ export const load = async ({ params }) => { return resp; } catch (e) { if ((e as APIError).code === ErrorCode.UserNotFound) { - throw error(404, e as APIError); + error(404, e as APIError); } throw e; diff --git a/frontend/src/routes/@[username]/+page.svelte b/frontend/src/routes/@[username]/+page.svelte index 56542fc..642e715 100644 --- a/frontend/src/routes/@[username]/+page.svelte +++ b/frontend/src/routes/@[username]/+page.svelte @@ -14,7 +14,7 @@ ModalBody, ModalFooter, Tooltip, - } from "sveltestrap"; + } from "@sveltestrap/sveltestrap"; import { DateTime, Duration, FixedOffsetZone, Zone } from "luxon"; import FieldCard from "$lib/components/FieldCard.svelte"; import PronounLink from "$lib/components/PronounLink.svelte"; diff --git a/frontend/src/routes/@[username]/ProfileFlag.svelte b/frontend/src/routes/@[username]/ProfileFlag.svelte index 3ef4c63..6862770 100644 --- a/frontend/src/routes/@[username]/ProfileFlag.svelte +++ b/frontend/src/routes/@[username]/ProfileFlag.svelte @@ -1,6 +1,6 @@ diff --git a/frontend/src/routes/@[username]/[memberName]/edit/fields/+page.svelte b/frontend/src/routes/@[username]/[memberName]/edit/fields/+page.svelte index a77b13a..08a456d 100644 --- a/frontend/src/routes/@[username]/[memberName]/edit/fields/+page.svelte +++ b/frontend/src/routes/@[username]/[memberName]/edit/fields/+page.svelte @@ -1,7 +1,7 @@ diff --git a/frontend/src/routes/@[username]/edit/+layout.svelte b/frontend/src/routes/@[username]/edit/+layout.svelte index 6bcb23b..de6dbf3 100644 --- a/frontend/src/routes/@[username]/edit/+layout.svelte +++ b/frontend/src/routes/@[username]/edit/+layout.svelte @@ -2,7 +2,7 @@ import { setContext } from "svelte"; import { writable } from "svelte/store"; import type { LayoutData } from "./$types"; - import { Button, ButtonGroup, Icon, Nav, NavItem } from "sveltestrap"; + import { Button, ButtonGroup, Icon, Nav, NavItem } from "@sveltestrap/sveltestrap"; import type { MeUser, APIError } from "$lib/api/entities"; import ErrorAlert from "$lib/components/ErrorAlert.svelte"; import { addToast, delToast } from "$lib/toast"; diff --git a/frontend/src/routes/@[username]/edit/+layout.ts b/frontend/src/routes/@[username]/edit/+layout.ts index 2fd9c4c..de77441 100644 --- a/frontend/src/routes/@[username]/edit/+layout.ts +++ b/frontend/src/routes/@[username]/edit/+layout.ts @@ -13,7 +13,7 @@ export const load = async ({ params }) => { const flags = await apiFetchClient("/users/@me/flags"); if (params.username !== user.name) { - throw redirect(303, `/@${user.name}/edit`); + redirect(303, `/@${user.name}/edit`); } return { @@ -22,7 +22,7 @@ export const load = async ({ params }) => { flags, }; } catch (e) { - if ("code" in e) throw error(500, e as APIError); + if ("code" in e) error(500, e as APIError); throw e; } }; diff --git a/frontend/src/routes/@[username]/edit/+page.svelte b/frontend/src/routes/@[username]/edit/+page.svelte index e727633..d5c2aeb 100644 --- a/frontend/src/routes/@[username]/edit/+page.svelte +++ b/frontend/src/routes/@[username]/edit/+page.svelte @@ -3,7 +3,7 @@ import type { Writable } from "svelte/store"; import prettyBytes from "pretty-bytes"; import { encode } from "base64-arraybuffer"; - import { FormGroup, Icon, Input } from "sveltestrap"; + import { FormGroup, Icon, Input } from "@sveltestrap/sveltestrap"; import { userAvatars, type MeUser } from "$lib/api/entities"; import FallbackImage from "$lib/components/FallbackImage.svelte"; import EditableName from "$lib/components/edit/EditableName.svelte"; diff --git a/frontend/src/routes/@[username]/edit/bio/+page.svelte b/frontend/src/routes/@[username]/edit/bio/+page.svelte index 2cbbf38..572fa35 100644 --- a/frontend/src/routes/@[username]/edit/bio/+page.svelte +++ b/frontend/src/routes/@[username]/edit/bio/+page.svelte @@ -4,7 +4,7 @@ import { MAX_DESCRIPTION_LENGTH, type MeUser } from "$lib/api/entities"; import { charCount, renderMarkdown } from "$lib/utils"; import MarkdownHelp from "$lib/components/edit/MarkdownHelp.svelte"; - import { Card, CardBody, CardHeader } from "sveltestrap"; + import { Card, CardBody, CardHeader } from "@sveltestrap/sveltestrap"; const user = getContext>("user"); diff --git a/frontend/src/routes/@[username]/edit/fields/+page.svelte b/frontend/src/routes/@[username]/edit/fields/+page.svelte index f09d89d..9ad8d0a 100644 --- a/frontend/src/routes/@[username]/edit/fields/+page.svelte +++ b/frontend/src/routes/@[username]/edit/fields/+page.svelte @@ -1,7 +1,7 @@ diff --git a/frontend/src/routes/settings/+layout.svelte b/frontend/src/routes/settings/+layout.svelte index fc225ee..1120447 100644 --- a/frontend/src/routes/settings/+layout.svelte +++ b/frontend/src/routes/settings/+layout.svelte @@ -9,7 +9,7 @@ Modal, ModalBody, ModalFooter, - } from "sveltestrap"; + } from "@sveltestrap/sveltestrap"; import { userStore } from "$lib/store"; import { goto } from "$app/navigation"; import { addToast } from "$lib/toast"; diff --git a/frontend/src/routes/settings/+layout.ts b/frontend/src/routes/settings/+layout.ts index 415bf6c..acf0e5e 100644 --- a/frontend/src/routes/settings/+layout.ts +++ b/frontend/src/routes/settings/+layout.ts @@ -40,7 +40,7 @@ export const load = (async ({ parent }) => { }; } catch (e) { if ((e as APIError).code !== ErrorCode.InternalServerError) { - throw redirect(303, "/auth/login"); + redirect(303, "/auth/login"); } throw e; } diff --git a/frontend/src/routes/settings/+page.svelte b/frontend/src/routes/settings/+page.svelte index 92451e1..58f5650 100644 --- a/frontend/src/routes/settings/+page.svelte +++ b/frontend/src/routes/settings/+page.svelte @@ -23,7 +23,7 @@ ModalFooter, ModalHeader, Table, - } from "sveltestrap"; + } from "@sveltestrap/sveltestrap"; import type { PageData } from "./$types"; import { onMount } from "svelte"; import { DateTime } from "luxon"; diff --git a/frontend/src/routes/settings/auth/+page.svelte b/frontend/src/routes/settings/auth/+page.svelte index 2d03bb5..c55d9bb 100644 --- a/frontend/src/routes/settings/auth/+page.svelte +++ b/frontend/src/routes/settings/auth/+page.svelte @@ -13,7 +13,7 @@ Modal, ModalBody, ModalFooter, - } from "sveltestrap"; + } from "@sveltestrap/sveltestrap"; import type { PageData } from "./$types"; export let data: PageData; diff --git a/frontend/src/routes/settings/export/+page.svelte b/frontend/src/routes/settings/export/+page.svelte index 31f87e7..97733f6 100644 --- a/frontend/src/routes/settings/export/+page.svelte +++ b/frontend/src/routes/settings/export/+page.svelte @@ -1,7 +1,7 @@ + +
+
    + {#each usedDefaultPreferences as pref (pref.id)} +
  • + + {pref.preference.tooltip} +
  • + {/each} +
+ {#if usedCustomPreferences} +
    + {#each usedCustomPreferences as pref (pref.id)} +
  • + + {pref.preference.tooltip} +
  • + {/each} +
+ {/if} +
diff --git a/frontend/src/routes/@[username]/[memberName]/+page.svelte b/frontend/src/routes/@[username]/[memberName]/+page.svelte index 206cbfd..1ecc942 100644 --- a/frontend/src/routes/@[username]/[memberName]/+page.svelte +++ b/frontend/src/routes/@[username]/[memberName]/+page.svelte @@ -22,6 +22,7 @@ import { addToast } from "$lib/toast"; import ProfileFlag from "../ProfileFlag.svelte"; import IconButton from "$lib/components/IconButton.svelte"; + import PreferencesCheatsheet from "../PreferencesCheatsheet.svelte"; export let data: PageData; @@ -154,6 +155,12 @@ {/each} +
From 44b667ff4322051019a90cd4b3d9a484734b87dc Mon Sep 17 00:00:00 2001 From: sam Date: Sat, 30 Dec 2023 02:33:58 +0100 Subject: [PATCH 03/14] add frontend CI --- .woodpecker.yml | 16 ++++++++++++++++ Makefile | 2 +- frontend/svelte.config.js | 2 +- 3 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 .woodpecker.yml diff --git a/.woodpecker.yml b/.woodpecker.yml new file mode 100644 index 0000000..5af005c --- /dev/null +++ b/.woodpecker.yml @@ -0,0 +1,16 @@ +steps: + frontend: + image: node + directory: frontend + environment: # SvelteKit expects these in the environment during build time. + - PRIVATE_SENTRY_DSN=non_existent_dsn + - PUBLIC_BASE_URL=http://pronouns.localhost + - PUBLIC_MEDIA_URL=http://pronouns.localhost/media + - PUBLIC_SHORT_BASE=http://prns.localhost + - PUBLIC_HCAPTCHA_SITEKEY=non_existent_sitekey + commands: + - corepack enable + - pnpm install + - pnpm check + - pnpm lint + - pnpm build diff --git a/Makefile b/Makefile index 1b15eff..8a7c089 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ all: generate backend frontend .PHONY: backend backend: - go build -v -o pronouns -ldflags="-buildid= -X codeberg.org/pronounscc/pronouns.cc/backend/server.Revision=`git rev-parse --short HEAD` -X codeberg.org/pronounscc/pronouns.cc/backend/server.Tag=`git describe --tags --long`" . + go build -v -o pronouns -ldflags="-buildid= -X codeberg.org/pronounscc/pronouns.cc/backend/server.Revision=`git rev-parse --short HEAD` -X codeberg.org/pronounscc/pronouns.cc/backend/server.Tag=`git describe --tags --long --always`" . .PHONY: generate generate: diff --git a/frontend/svelte.config.js b/frontend/svelte.config.js index c9182bf..46d780b 100644 --- a/frontend/svelte.config.js +++ b/frontend/svelte.config.js @@ -11,7 +11,7 @@ const config = { kit: { adapter: adapter(), version: { - name: child_process.execSync("git describe --tags --long").toString().trim(), + name: child_process.execSync("git describe --tags --long --always").toString().trim(), }, }, }; From e37b5be376c6446dca5a8a951cf55ed346d93572 Mon Sep 17 00:00:00 2001 From: sam Date: Sat, 30 Dec 2023 03:51:01 +0100 Subject: [PATCH 04/14] add backend CI --- .golangci.yml | 2 ++ .woodpecker/.backend.yml | 9 +++++++++ .woodpecker.yml => .woodpecker/.frontend.yml | 2 +- 3 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 .golangci.yml create mode 100644 .woodpecker/.backend.yml rename .woodpecker.yml => .woodpecker/.frontend.yml (97%) diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..29471e1 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,2 @@ +run: + issues-exit-code: 0 # lol diff --git a/.woodpecker/.backend.yml b/.woodpecker/.backend.yml new file mode 100644 index 0000000..71abad3 --- /dev/null +++ b/.woodpecker/.backend.yml @@ -0,0 +1,9 @@ +steps: + check: + image: golang:alpine + commands: + - apk update && apk add curl vips-dev build-base + - make backend + # Install golangci-lint + - curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.55.2 + - golangci-lint run diff --git a/.woodpecker.yml b/.woodpecker/.frontend.yml similarity index 97% rename from .woodpecker.yml rename to .woodpecker/.frontend.yml index 5af005c..a10ef11 100644 --- a/.woodpecker.yml +++ b/.woodpecker/.frontend.yml @@ -1,5 +1,5 @@ steps: - frontend: + check: image: node directory: frontend environment: # SvelteKit expects these in the environment during build time. From c13c4e90b669b773360c011ec55d88433b220233 Mon Sep 17 00:00:00 2001 From: sam Date: Sat, 30 Dec 2023 04:27:08 +0100 Subject: [PATCH 05/14] don't ignore errors in tx.Rollback() --- .golangci.yml | 2 -- backend/db/export.go | 2 +- backend/db/invites.go | 8 +++++++- backend/db/member.go | 8 +++++++- backend/main.go | 3 ++- backend/routes/v1/auth/discord.go | 8 +++++++- backend/routes/v1/auth/fedi_mastodon.go | 8 +++++++- backend/routes/v1/auth/fedi_misskey.go | 8 +++++++- backend/routes/v1/auth/google.go | 8 +++++++- backend/routes/v1/auth/tokens.go | 9 ++++++++- backend/routes/v1/auth/tumblr.go | 8 +++++++- backend/routes/v1/member/create_member.go | 8 +++++++- backend/routes/v1/member/patch_member.go | 8 +++++++- backend/routes/v1/mod/resolve_report.go | 8 +++++++- backend/routes/v1/user/delete_user.go | 9 ++++++++- backend/routes/v1/user/flags.go | 15 ++++++++++++-- backend/routes/v1/user/patch_user.go | 8 +++++++- backend/server/server.go | 24 +++++++++++------------ scripts/cleandb/main.go | 10 +++++++++- scripts/seeddb/main.go | 9 ++++++++- scripts/snowflakes/main.go | 8 +++++++- 21 files changed, 145 insertions(+), 34 deletions(-) delete mode 100644 .golangci.yml diff --git a/.golangci.yml b/.golangci.yml deleted file mode 100644 index 29471e1..0000000 --- a/.golangci.yml +++ /dev/null @@ -1,2 +0,0 @@ -run: - issues-exit-code: 0 # lol diff --git a/backend/db/export.go b/backend/db/export.go index 6141aac..5095445 100644 --- a/backend/db/export.go +++ b/backend/db/export.go @@ -79,7 +79,7 @@ func (db *DB) CreateExport(ctx context.Context, userID xid.ID, filename string, return de, errors.Wrap(err, "building query") } - pgxscan.Get(ctx, db, &de, sql, args...) + err = pgxscan.Get(ctx, db, &de, sql, args...) if err != nil { return de, errors.Wrap(err, "executing sql") } diff --git a/backend/db/invites.go b/backend/db/invites.go index d56662e..d13ab0e 100644 --- a/backend/db/invites.go +++ b/backend/db/invites.go @@ -6,6 +6,7 @@ import ( "encoding/base64" "time" + "codeberg.org/pronounscc/pronouns.cc/backend/log" "emperror.dev/errors" "github.com/georgysavva/scany/v2/pgxscan" "github.com/jackc/pgx/v5" @@ -43,7 +44,12 @@ func (db *DB) CreateInvite(ctx context.Context, userID xid.ID) (i Invite, err er if err != nil { return i, errors.Wrap(err, "beginning transaction") } - defer tx.Rollback(ctx) + defer func() { + err := tx.Rollback(ctx) + if err != nil && !errors.Is(err, pgx.ErrTxClosed) { + log.Error("rolling back transaction:", err) + } + }() var maxInvites, inviteCount int err = tx.QueryRow(ctx, "SELECT max_invites FROM users WHERE id = $1", userID).Scan(&maxInvites) diff --git a/backend/db/member.go b/backend/db/member.go index 6eb444c..a50c431 100644 --- a/backend/db/member.go +++ b/backend/db/member.go @@ -7,6 +7,7 @@ import ( "time" "codeberg.org/pronounscc/pronouns.cc/backend/common" + "codeberg.org/pronounscc/pronouns.cc/backend/log" "emperror.dev/errors" "github.com/Masterminds/squirrel" "github.com/georgysavva/scany/v2/pgxscan" @@ -287,7 +288,12 @@ func (db *DB) RerollMemberSID(ctx context.Context, userID, memberID xid.ID) (new if err != nil { return "", errors.Wrap(err, "beginning transaction") } - defer tx.Rollback(ctx) + defer func() { + err := tx.Rollback(ctx) + if err != nil && !errors.Is(err, pgx.ErrTxClosed) { + log.Error("rolling back transaction:", err) + } + }() sql, args, err := sq.Update("members"). Set("sid", squirrel.Expr("find_free_member_sid()")). diff --git a/backend/main.go b/backend/main.go index d9efd98..c17679e 100644 --- a/backend/main.go +++ b/backend/main.go @@ -26,7 +26,8 @@ var Command = &cli.Command{ func run(c *cli.Context) error { // initialize sentry if dsn := os.Getenv("SENTRY_DSN"); dsn != "" { - sentry.Init(sentry.ClientOptions{ + // We don't need to check the error here--it's fine if no DSN is set. + _ = sentry.Init(sentry.ClientOptions{ Dsn: dsn, Debug: os.Getenv("DEBUG") == "true", Release: server.Tag, diff --git a/backend/routes/v1/auth/discord.go b/backend/routes/v1/auth/discord.go index 2084b52..b8a72f3 100644 --- a/backend/routes/v1/auth/discord.go +++ b/backend/routes/v1/auth/discord.go @@ -11,6 +11,7 @@ import ( "emperror.dev/errors" "github.com/bwmarrin/discordgo" "github.com/go-chi/render" + "github.com/jackc/pgx/v5" "github.com/mediocregopher/radix/v4" "github.com/rs/xid" "golang.org/x/oauth2" @@ -291,7 +292,12 @@ func (s *Server) discordSignup(w http.ResponseWriter, r *http.Request) error { if err != nil { return errors.Wrap(err, "beginning transaction") } - defer tx.Rollback(ctx) + defer func() { + err := tx.Rollback(ctx) + if err != nil && !errors.Is(err, pgx.ErrTxClosed) { + log.Error("rolling back transaction:", err) + } + }() du := new(discordgo.User) err = s.DB.GetJSON(ctx, "discord:"+req.Ticket, &du) diff --git a/backend/routes/v1/auth/fedi_mastodon.go b/backend/routes/v1/auth/fedi_mastodon.go index bb07958..f69a2b3 100644 --- a/backend/routes/v1/auth/fedi_mastodon.go +++ b/backend/routes/v1/auth/fedi_mastodon.go @@ -11,6 +11,7 @@ import ( "codeberg.org/pronounscc/pronouns.cc/backend/server" "emperror.dev/errors" "github.com/go-chi/render" + "github.com/jackc/pgx/v5" "github.com/mediocregopher/radix/v4" "github.com/rs/xid" ) @@ -319,7 +320,12 @@ func (s *Server) mastodonSignup(w http.ResponseWriter, r *http.Request) error { if err != nil { return errors.Wrap(err, "beginning transaction") } - defer tx.Rollback(ctx) + defer func() { + err := tx.Rollback(ctx) + if err != nil && !errors.Is(err, pgx.ErrTxClosed) { + log.Error("rolling back transaction:", err) + } + }() mu := new(partialMastodonAccount) err = s.DB.GetJSON(ctx, "mastodon:"+req.Ticket, &mu) diff --git a/backend/routes/v1/auth/fedi_misskey.go b/backend/routes/v1/auth/fedi_misskey.go index ebf6e22..d162f77 100644 --- a/backend/routes/v1/auth/fedi_misskey.go +++ b/backend/routes/v1/auth/fedi_misskey.go @@ -12,6 +12,7 @@ import ( "codeberg.org/pronounscc/pronouns.cc/backend/server" "emperror.dev/errors" "github.com/go-chi/render" + "github.com/jackc/pgx/v5" "github.com/mediocregopher/radix/v4" "github.com/rs/xid" ) @@ -247,7 +248,12 @@ func (s *Server) misskeySignup(w http.ResponseWriter, r *http.Request) error { if err != nil { return errors.Wrap(err, "beginning transaction") } - defer tx.Rollback(ctx) + defer func() { + err := tx.Rollback(ctx) + if err != nil && !errors.Is(err, pgx.ErrTxClosed) { + log.Error("rolling back transaction:", err) + } + }() mu := new(partialMisskeyAccount) err = s.DB.GetJSON(ctx, "misskey:"+req.Ticket, &mu) diff --git a/backend/routes/v1/auth/google.go b/backend/routes/v1/auth/google.go index 026a6d1..7904889 100644 --- a/backend/routes/v1/auth/google.go +++ b/backend/routes/v1/auth/google.go @@ -10,6 +10,7 @@ import ( "codeberg.org/pronounscc/pronouns.cc/backend/server" "emperror.dev/errors" "github.com/go-chi/render" + "github.com/jackc/pgx/v5" "github.com/mediocregopher/radix/v4" "github.com/rs/xid" "golang.org/x/oauth2" @@ -294,7 +295,12 @@ func (s *Server) googleSignup(w http.ResponseWriter, r *http.Request) error { if err != nil { return errors.Wrap(err, "beginning transaction") } - defer tx.Rollback(ctx) + defer func() { + err := tx.Rollback(ctx) + if err != nil && !errors.Is(err, pgx.ErrTxClosed) { + log.Error("rolling back transaction:", err) + } + }() gu := new(partialGoogleUser) err = s.DB.GetJSON(ctx, "google:"+req.Ticket, &gu) diff --git a/backend/routes/v1/auth/tokens.go b/backend/routes/v1/auth/tokens.go index e48662d..0f8b8b8 100644 --- a/backend/routes/v1/auth/tokens.go +++ b/backend/routes/v1/auth/tokens.go @@ -5,9 +5,11 @@ import ( "time" "codeberg.org/pronounscc/pronouns.cc/backend/db" + "codeberg.org/pronounscc/pronouns.cc/backend/log" "codeberg.org/pronounscc/pronouns.cc/backend/server" "emperror.dev/errors" "github.com/go-chi/render" + "github.com/jackc/pgx/v5" "github.com/rs/xid" ) @@ -63,7 +65,12 @@ func (s *Server) deleteToken(w http.ResponseWriter, r *http.Request) error { if err != nil { return errors.Wrap(err, "beginning transaction") } - defer tx.Rollback(ctx) + defer func() { + err := tx.Rollback(ctx) + if err != nil && !errors.Is(err, pgx.ErrTxClosed) { + log.Error("rolling back transaction:", err) + } + }() err = s.DB.InvalidateAllTokens(ctx, tx, claims.UserID) if err != nil { diff --git a/backend/routes/v1/auth/tumblr.go b/backend/routes/v1/auth/tumblr.go index 52dcdec..3463c9d 100644 --- a/backend/routes/v1/auth/tumblr.go +++ b/backend/routes/v1/auth/tumblr.go @@ -12,6 +12,7 @@ import ( "codeberg.org/pronounscc/pronouns.cc/backend/server" "emperror.dev/errors" "github.com/go-chi/render" + "github.com/jackc/pgx/v5" "github.com/mediocregopher/radix/v4" "github.com/rs/xid" "golang.org/x/oauth2" @@ -327,7 +328,12 @@ func (s *Server) tumblrSignup(w http.ResponseWriter, r *http.Request) error { if err != nil { return errors.Wrap(err, "beginning transaction") } - defer tx.Rollback(ctx) + defer func() { + err := tx.Rollback(ctx) + if err != nil && !errors.Is(err, pgx.ErrTxClosed) { + log.Error("rolling back transaction:", err) + } + }() tui := new(tumblrUserInfo) err = s.DB.GetJSON(ctx, "tumblr:"+req.Ticket, &tui) diff --git a/backend/routes/v1/member/create_member.go b/backend/routes/v1/member/create_member.go index c94915a..288aafc 100644 --- a/backend/routes/v1/member/create_member.go +++ b/backend/routes/v1/member/create_member.go @@ -11,6 +11,7 @@ import ( "codeberg.org/pronounscc/pronouns.cc/backend/server" "emperror.dev/errors" "github.com/go-chi/render" + "github.com/jackc/pgx/v5" ) type CreateMemberRequest struct { @@ -119,7 +120,12 @@ func (s *Server) createMember(w http.ResponseWriter, r *http.Request) (err error if err != nil { return errors.Wrap(err, "starting transaction") } - defer tx.Rollback(ctx) + defer func() { + err := tx.Rollback(ctx) + if err != nil && !errors.Is(err, pgx.ErrTxClosed) { + log.Error("rolling back transaction:", err) + } + }() m, err := s.DB.CreateMember(ctx, tx, claims.UserID, cmr.Name, cmr.DisplayName, cmr.Bio, cmr.Links) if err != nil { diff --git a/backend/routes/v1/member/patch_member.go b/backend/routes/v1/member/patch_member.go index f8cee31..c26cf37 100644 --- a/backend/routes/v1/member/patch_member.go +++ b/backend/routes/v1/member/patch_member.go @@ -13,6 +13,7 @@ import ( "emperror.dev/errors" "github.com/go-chi/chi/v5" "github.com/go-chi/render" + "github.com/jackc/pgx/v5" "github.com/rs/xid" ) @@ -246,7 +247,12 @@ func (s *Server) patchMember(w http.ResponseWriter, r *http.Request) error { log.Errorf("creating transaction: %v", err) return errors.Wrap(err, "creating transaction") } - defer tx.Rollback(ctx) + defer func() { + err := tx.Rollback(ctx) + if err != nil && !errors.Is(err, pgx.ErrTxClosed) { + log.Error("rolling back transaction:", err) + } + }() m, err = s.DB.UpdateMember(ctx, tx, m.ID, req.Name, req.DisplayName, req.Bio, req.Unlisted, req.Links, avatarHash) if err != nil { diff --git a/backend/routes/v1/mod/resolve_report.go b/backend/routes/v1/mod/resolve_report.go index 77e4b8d..c36cb86 100644 --- a/backend/routes/v1/mod/resolve_report.go +++ b/backend/routes/v1/mod/resolve_report.go @@ -10,6 +10,7 @@ import ( "emperror.dev/errors" "github.com/go-chi/chi/v5" "github.com/go-chi/render" + "github.com/jackc/pgx/v5" ) type resolveReportRequest struct { @@ -43,7 +44,12 @@ func (s *Server) resolveReport(w http.ResponseWriter, r *http.Request) error { log.Errorf("creating transaction: %v", err) return errors.Wrap(err, "creating transaction") } - defer tx.Rollback(ctx) + defer func() { + err := tx.Rollback(ctx) + if err != nil && !errors.Is(err, pgx.ErrTxClosed) { + log.Error("rolling back transaction:", err) + } + }() report, err := s.DB.Report(ctx, tx, id) if err != nil { diff --git a/backend/routes/v1/user/delete_user.go b/backend/routes/v1/user/delete_user.go index 1523978..1132f05 100644 --- a/backend/routes/v1/user/delete_user.go +++ b/backend/routes/v1/user/delete_user.go @@ -3,9 +3,11 @@ package user import ( "net/http" + "codeberg.org/pronounscc/pronouns.cc/backend/log" "codeberg.org/pronounscc/pronouns.cc/backend/server" "emperror.dev/errors" "github.com/go-chi/render" + "github.com/jackc/pgx/v5" ) func (s *Server) deleteUser(w http.ResponseWriter, r *http.Request) error { @@ -20,7 +22,12 @@ func (s *Server) deleteUser(w http.ResponseWriter, r *http.Request) error { if err != nil { return errors.Wrap(err, "creating transaction") } - defer tx.Rollback(ctx) + defer func() { + err := tx.Rollback(ctx) + if err != nil && !errors.Is(err, pgx.ErrTxClosed) { + log.Error("rolling back transaction:", err) + } + }() err = s.DB.DeleteUser(ctx, tx, claims.UserID, true, "") if err != nil { diff --git a/backend/routes/v1/user/flags.go b/backend/routes/v1/user/flags.go index b9c3ced..c7b6ad7 100644 --- a/backend/routes/v1/user/flags.go +++ b/backend/routes/v1/user/flags.go @@ -13,6 +13,7 @@ import ( "emperror.dev/errors" "github.com/go-chi/chi/v5" "github.com/go-chi/render" + "github.com/jackc/pgx/v5" "github.com/rs/xid" ) @@ -80,7 +81,12 @@ func (s *Server) postUserFlag(w http.ResponseWriter, r *http.Request) error { if err != nil { return errors.Wrap(err, "starting transaction") } - defer tx.Rollback(ctx) + defer func() { + err := tx.Rollback(ctx) + if err != nil && !errors.Is(err, pgx.ErrTxClosed) { + log.Error("rolling back transaction:", err) + } + }() flag, err := s.DB.CreateFlag(ctx, tx, claims.UserID, req.Name, req.Description) if err != nil { @@ -192,7 +198,12 @@ func (s *Server) patchUserFlag(w http.ResponseWriter, r *http.Request) error { if err != nil { return errors.Wrap(err, "beginning transaction") } - defer tx.Rollback(ctx) + defer func() { + err := tx.Rollback(ctx) + if err != nil && !errors.Is(err, pgx.ErrTxClosed) { + log.Error("rolling back transaction:", err) + } + }() flag, err = s.DB.EditFlag(ctx, tx, flag.ID, req.Name, req.Description, nil) if err != nil { diff --git a/backend/routes/v1/user/patch_user.go b/backend/routes/v1/user/patch_user.go index ca489ce..6e4f6ab 100644 --- a/backend/routes/v1/user/patch_user.go +++ b/backend/routes/v1/user/patch_user.go @@ -12,6 +12,7 @@ import ( "emperror.dev/errors" "github.com/go-chi/render" "github.com/google/uuid" + "github.com/jackc/pgx/v5" "github.com/rs/xid" ) @@ -221,7 +222,12 @@ func (s *Server) patchUser(w http.ResponseWriter, r *http.Request) error { log.Errorf("creating transaction: %v", err) return errors.Wrap(err, "creating transaction") } - defer tx.Rollback(ctx) + defer func() { + err := tx.Rollback(ctx) + if err != nil && !errors.Is(err, pgx.ErrTxClosed) { + log.Error("rolling back transaction:", err) + } + }() // update username if req.Username != nil && *req.Username != u.Username { diff --git a/backend/server/server.go b/backend/server/server.go index bfc785d..30cd552 100644 --- a/backend/server/server.go +++ b/backend/server/server.go @@ -100,23 +100,23 @@ func New() (*Server, error) { // set scopes // users - rateLimiter.Scope("GET", "/users/*", 60) - rateLimiter.Scope("PATCH", "/users/@me", 10) + _ = rateLimiter.Scope("GET", "/users/*", 60) + _ = rateLimiter.Scope("PATCH", "/users/@me", 10) // members - rateLimiter.Scope("GET", "/users/*/members", 60) - rateLimiter.Scope("GET", "/users/*/members/*", 60) + _ = rateLimiter.Scope("GET", "/users/*/members", 60) + _ = rateLimiter.Scope("GET", "/users/*/members/*", 60) - rateLimiter.Scope("POST", "/members", 10) - rateLimiter.Scope("GET", "/members/*", 60) - rateLimiter.Scope("PATCH", "/members/*", 20) - rateLimiter.Scope("DELETE", "/members/*", 5) + _ = rateLimiter.Scope("POST", "/members", 10) + _ = rateLimiter.Scope("GET", "/members/*", 60) + _ = rateLimiter.Scope("PATCH", "/members/*", 20) + _ = rateLimiter.Scope("DELETE", "/members/*", 5) // auth - rateLimiter.Scope("*", "/auth/*", 20) - rateLimiter.Scope("*", "/auth/tokens", 10) - rateLimiter.Scope("*", "/auth/invites", 10) - rateLimiter.Scope("POST", "/auth/discord/*", 10) + _ = rateLimiter.Scope("*", "/auth/*", 20) + _ = rateLimiter.Scope("*", "/auth/tokens", 10) + _ = rateLimiter.Scope("*", "/auth/invites", 10) + _ = rateLimiter.Scope("POST", "/auth/discord/*", 10) s.Router.Use(rateLimiter.Handler()) diff --git a/scripts/cleandb/main.go b/scripts/cleandb/main.go index 317951b..9049861 100644 --- a/scripts/cleandb/main.go +++ b/scripts/cleandb/main.go @@ -2,12 +2,15 @@ package cleandb import ( "context" + "errors" "fmt" "os" "time" dbpkg "codeberg.org/pronounscc/pronouns.cc/backend/db" + "codeberg.org/pronounscc/pronouns.cc/backend/log" "github.com/georgysavva/scany/v2/pgxscan" + "github.com/jackc/pgx/v5" "github.com/joho/godotenv" "github.com/rs/xid" "github.com/urfave/cli/v2" @@ -77,7 +80,12 @@ func run(c *cli.Context) error { fmt.Printf("error starting transaction: %v\n", err) return err } - defer tx.Rollback(ctx) + defer func() { + err := tx.Rollback(ctx) + if err != nil && !errors.Is(err, pgx.ErrTxClosed) { + log.Error("rolling back transaction:", err) + } + }() inactiveUsers, err := db.InactiveUsers(ctx, tx) if err != nil { diff --git a/scripts/seeddb/main.go b/scripts/seeddb/main.go index c2e9f26..bbe20f5 100644 --- a/scripts/seeddb/main.go +++ b/scripts/seeddb/main.go @@ -1,10 +1,12 @@ package seeddb import ( + "errors" "log" "os" "codeberg.org/pronounscc/pronouns.cc/backend/db" + "github.com/jackc/pgx/v5" "github.com/jackc/pgx/v5/pgxpool" "github.com/joho/godotenv" "github.com/urfave/cli/v2" @@ -82,7 +84,12 @@ func run(c *cli.Context) error { log.Println("error beginning transaction:", err) return err } - defer tx.Rollback(ctx) + defer func() { + err := tx.Rollback(ctx) + if err != nil && !errors.Is(err, pgx.ErrTxClosed) { + log.Println("error rolling back transaction:", err) + } + }() for i, su := range seed.Users { u, err := pg.CreateUser(ctx, tx, su.Username) diff --git a/scripts/snowflakes/main.go b/scripts/snowflakes/main.go index 382035a..e88fe26 100644 --- a/scripts/snowflakes/main.go +++ b/scripts/snowflakes/main.go @@ -1,6 +1,7 @@ package snowflakes import ( + "errors" "os" "time" @@ -39,7 +40,12 @@ func run(c *cli.Context) error { log.Error("creating transaction:", err) return err } - defer tx.Rollback(c.Context) + defer func() { + err := tx.Rollback(c.Context) + if err != nil && !errors.Is(err, pgx.ErrTxClosed) { + log.Error("rolling back transaction:", err) + } + }() var userIDs []xid.ID err = pgxscan.Select(c.Context, conn, &userIDs, "SELECT id FROM users WHERE snowflake_id IS NULL") From 00abe1cb32c3bbbe84e3e29468c7f9354b5c092c Mon Sep 17 00:00:00 2001 From: sam Date: Sat, 30 Dec 2023 04:41:22 +0100 Subject: [PATCH 06/14] fix: let users select the Google account to log in with every time --- backend/routes/v1/auth/routes.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/routes/v1/auth/routes.go b/backend/routes/v1/auth/routes.go index 103d43e..2e1a724 100644 --- a/backend/routes/v1/auth/routes.go +++ b/backend/routes/v1/auth/routes.go @@ -185,7 +185,7 @@ func (s *Server) oauthURLs(w http.ResponseWriter, r *http.Request) error { if googleOAuthConfig.ClientID != "" { googleCfg := googleOAuthConfig googleCfg.RedirectURL = req.CallbackDomain + "/auth/login/google" - resp.Google = googleCfg.AuthCodeURL(state) + resp.Google = googleCfg.AuthCodeURL(state) + "&prompt=select_account" } render.JSON(w, r, resp) From ac603ac18eeab598159371d8c46d095a1b3555fc Mon Sep 17 00:00:00 2001 From: sam Date: Sat, 30 Dec 2023 15:13:24 +0100 Subject: [PATCH 07/14] fix(frontend): fix type errors --- frontend/src/app.d.ts | 25 +++---------------- .../src/routes/@[username]/+page.server.ts | 2 +- .../@[username]/[memberName]/+page.server.ts | 4 +-- .../@[username]/[memberName]/edit/+layout.ts | 5 ++-- .../src/routes/@[username]/edit/+layout.ts | 5 ++-- .../src/routes/[username]/+page.server.ts | 2 +- frontend/src/routes/edit/member/[id]/+page.ts | 2 +- frontend/src/routes/edit/profile/+page.ts | 2 +- frontend/src/routes/page/about/+page.svelte | 1 + .../src/routes/page/changelog/+page.svelte | 1 + frontend/src/routes/page/privacy/+page.svelte | 1 + frontend/src/routes/page/terms/+page.svelte | 1 + .../pronouns/[...pronouns]/+page.svelte | 2 +- frontend/src/routes/settings/export/+page.ts | 2 +- frontend/src/svelte-hcaptcha.d.ts | 18 +++++++++++++ 15 files changed, 39 insertions(+), 34 deletions(-) create mode 100644 frontend/src/svelte-hcaptcha.d.ts diff --git a/frontend/src/app.d.ts b/frontend/src/app.d.ts index ba59572..9489da5 100644 --- a/frontend/src/app.d.ts +++ b/frontend/src/app.d.ts @@ -1,38 +1,19 @@ // See https://kit.svelte.dev/docs/types#app -import type { APIError, ErrorCode } from "$lib/api/entities"; +import type { ErrorCode } from "$lib/api/entities"; // for information about these interfaces declare global { namespace App { - type Error = { + interface Error { code: ErrorCode; message?: string | undefined; details?: string | undefined; - } | APIError + } // interface Locals {} // interface PageData {} // interface Platform {} } } -declare module "svelte-hcaptcha" { - import type { SvelteComponent } from "svelte"; - - export interface HCaptchaProps { - sitekey?: string; - apihost?: string; - hl?: string; - reCaptchaCompat?: boolean; - theme?: CaptchaTheme; - size?: string; - } - - declare class HCaptcha extends SvelteComponent { - $$prop_def: HCaptchaProps; - } - - export default HCaptcha; -} - export {}; diff --git a/frontend/src/routes/@[username]/+page.server.ts b/frontend/src/routes/@[username]/+page.server.ts index 1e7b8af..0ae4617 100644 --- a/frontend/src/routes/@[username]/+page.server.ts +++ b/frontend/src/routes/@[username]/+page.server.ts @@ -11,7 +11,7 @@ export const load = async ({ params }) => { return resp; } catch (e) { if ((e as APIError).code === ErrorCode.UserNotFound) { - error(404, e as APIError); + error(404, e as App.Error); } throw e; diff --git a/frontend/src/routes/@[username]/[memberName]/+page.server.ts b/frontend/src/routes/@[username]/[memberName]/+page.server.ts index ad5925d..02aff1b 100644 --- a/frontend/src/routes/@[username]/[memberName]/+page.server.ts +++ b/frontend/src/routes/@[username]/[memberName]/+page.server.ts @@ -14,9 +14,9 @@ export const load = async ({ params }) => { (e as APIError).code === ErrorCode.UserNotFound || (e as APIError).code === ErrorCode.MemberNotFound ) { - error(404, e as APIError); + error(404, e as App.Error); } - error(500, e as APIError); + error(500, e as App.Error); } }; diff --git a/frontend/src/routes/@[username]/[memberName]/edit/+layout.ts b/frontend/src/routes/@[username]/[memberName]/edit/+layout.ts index e6333c0..8493fa6 100644 --- a/frontend/src/routes/@[username]/[memberName]/edit/+layout.ts +++ b/frontend/src/routes/@[username]/[memberName]/edit/+layout.ts @@ -41,8 +41,9 @@ export const load = (async ({ params }) => { pronouns: pronouns.autocomplete, flags, }; - } catch (e) { - if ("code" in e) error(500, e as APIError); + // eslint-disable-next-line @typescript-eslint/no-explicit-any + } catch (e: any) { + if ("code" in e) error(500, e as App.Error); throw e; } }) satisfies LayoutLoad; diff --git a/frontend/src/routes/@[username]/edit/+layout.ts b/frontend/src/routes/@[username]/edit/+layout.ts index de77441..23e176d 100644 --- a/frontend/src/routes/@[username]/edit/+layout.ts +++ b/frontend/src/routes/@[username]/edit/+layout.ts @@ -21,8 +21,9 @@ export const load = async ({ params }) => { pronouns: pronouns.autocomplete, flags, }; - } catch (e) { - if ("code" in e) error(500, e as APIError); + // eslint-disable-next-line @typescript-eslint/no-explicit-any + } catch (e: any) { + if ("code" in e) error(500, e as App.Error); throw e; } }; diff --git a/frontend/src/routes/[username]/+page.server.ts b/frontend/src/routes/[username]/+page.server.ts index b291ccb..6784dee 100644 --- a/frontend/src/routes/[username]/+page.server.ts +++ b/frontend/src/routes/[username]/+page.server.ts @@ -11,7 +11,7 @@ export const load = async ({ params }) => { redirect(303, `/@${resp.name}`); } catch (e) { if ((e as APIError).code === ErrorCode.UserNotFound) { - error(404, e as APIError); + error(404, e as App.Error); } throw e; diff --git a/frontend/src/routes/edit/member/[id]/+page.ts b/frontend/src/routes/edit/member/[id]/+page.ts index 96a64a2..1d6132c 100644 --- a/frontend/src/routes/edit/member/[id]/+page.ts +++ b/frontend/src/routes/edit/member/[id]/+page.ts @@ -23,7 +23,7 @@ export const load = async ({ params }) => { (e as APIError).code === ErrorCode.InvalidToken || (e as APIError).code === ErrorCode.NotOwnMember ) { - error(403, e as APIError); + error(403, e as App.Error); } throw e; diff --git a/frontend/src/routes/edit/profile/+page.ts b/frontend/src/routes/edit/profile/+page.ts index 71cd278..085adf3 100644 --- a/frontend/src/routes/edit/profile/+page.ts +++ b/frontend/src/routes/edit/profile/+page.ts @@ -14,7 +14,7 @@ export const load = async () => { (e as APIError).code === ErrorCode.Forbidden || (e as APIError).code === ErrorCode.InvalidToken ) { - error(403, e as APIError); + error(403, e as App.Error); } throw e; diff --git a/frontend/src/routes/page/about/+page.svelte b/frontend/src/routes/page/about/+page.svelte index ea19018..82fb6eb 100644 --- a/frontend/src/routes/page/about/+page.svelte +++ b/frontend/src/routes/page/about/+page.svelte @@ -1,4 +1,5 @@ diff --git a/frontend/src/routes/page/changelog/+page.svelte b/frontend/src/routes/page/changelog/+page.svelte index 51cc848..890f472 100644 --- a/frontend/src/routes/page/changelog/+page.svelte +++ b/frontend/src/routes/page/changelog/+page.svelte @@ -1,5 +1,6 @@ diff --git a/frontend/src/routes/page/terms/+page.svelte b/frontend/src/routes/page/terms/+page.svelte index ea126d0..fc3734e 100644 --- a/frontend/src/routes/page/terms/+page.svelte +++ b/frontend/src/routes/page/terms/+page.svelte @@ -1,4 +1,5 @@ diff --git a/frontend/src/routes/pronouns/[...pronouns]/+page.svelte b/frontend/src/routes/pronouns/[...pronouns]/+page.svelte index fd9536f..09a4329 100644 --- a/frontend/src/routes/pronouns/[...pronouns]/+page.svelte +++ b/frontend/src/routes/pronouns/[...pronouns]/+page.svelte @@ -1,6 +1,6 @@ diff --git a/frontend/src/routes/page/changelog/+page.svelte b/frontend/src/routes/page/changelog/+page.svelte index 890f472..bd98e56 100644 --- a/frontend/src/routes/page/changelog/+page.svelte +++ b/frontend/src/routes/page/changelog/+page.svelte @@ -1,5 +1,7 @@ diff --git a/frontend/src/routes/page/terms/+page.svelte b/frontend/src/routes/page/terms/+page.svelte index fc3734e..92044e4 100644 --- a/frontend/src/routes/page/terms/+page.svelte +++ b/frontend/src/routes/page/terms/+page.svelte @@ -1,4 +1,6 @@ diff --git a/frontend/src/routes/settings/+page.svelte b/frontend/src/routes/settings/+page.svelte index 58f5650..e2c57db 100644 --- a/frontend/src/routes/settings/+page.svelte +++ b/frontend/src/routes/settings/+page.svelte @@ -25,7 +25,6 @@ Table, } from "@sveltestrap/sveltestrap"; import type { PageData } from "./$types"; - import { onMount } from "svelte"; import { DateTime } from "luxon"; export let data: PageData; From 1339550c808218ad92ae99cbd5f82d6b2a72c137 Mon Sep 17 00:00:00 2001 From: sam Date: Sat, 30 Dec 2023 15:38:23 +0100 Subject: [PATCH 10/14] fix: don't require a valid sentry dsn for the frontend --- .woodpecker/.frontend.yml | 2 +- frontend/src/hooks.server.ts | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.woodpecker/.frontend.yml b/.woodpecker/.frontend.yml index a10ef11..228ce76 100644 --- a/.woodpecker/.frontend.yml +++ b/.woodpecker/.frontend.yml @@ -3,7 +3,7 @@ steps: image: node directory: frontend environment: # SvelteKit expects these in the environment during build time. - - PRIVATE_SENTRY_DSN=non_existent_dsn + - PRIVATE_SENTRY_DSN= - PUBLIC_BASE_URL=http://pronouns.localhost - PUBLIC_MEDIA_URL=http://pronouns.localhost/media - PUBLIC_SHORT_BASE=http://prns.localhost diff --git a/frontend/src/hooks.server.ts b/frontend/src/hooks.server.ts index e073554..670f914 100644 --- a/frontend/src/hooks.server.ts +++ b/frontend/src/hooks.server.ts @@ -2,7 +2,9 @@ import { PRIVATE_SENTRY_DSN } from "$env/static/private"; import * as Sentry from "@sentry/node"; import type { HandleServerError } from "@sveltejs/kit"; -Sentry.init({ dsn: PRIVATE_SENTRY_DSN }); +if (PRIVATE_SENTRY_DSN) { + Sentry.init({ dsn: PRIVATE_SENTRY_DSN }); +} export const handleError = (({ error, event }) => { console.log(error); From b29a0c86db27cb7f371625a9ae0f08c2d9918a3d Mon Sep 17 00:00:00 2001 From: sam Date: Sun, 31 Dec 2023 15:14:50 +0100 Subject: [PATCH 11/14] only run ci on main [skip ci] --- .woodpecker/.backend.yml | 3 +++ .woodpecker/.frontend.yml | 3 +++ 2 files changed, 6 insertions(+) diff --git a/.woodpecker/.backend.yml b/.woodpecker/.backend.yml index 71abad3..811aa7e 100644 --- a/.woodpecker/.backend.yml +++ b/.woodpecker/.backend.yml @@ -1,3 +1,6 @@ +when: + branch: main + steps: check: image: golang:alpine diff --git a/.woodpecker/.frontend.yml b/.woodpecker/.frontend.yml index 228ce76..abc7e2b 100644 --- a/.woodpecker/.frontend.yml +++ b/.woodpecker/.frontend.yml @@ -1,3 +1,6 @@ +when: + branch: main + steps: check: image: node From 40672d6d4180c37b2f909e935f9364e52c5ad7d1 Mon Sep 17 00:00:00 2001 From: sam Date: Fri, 5 Jan 2024 15:24:42 +0100 Subject: [PATCH 12/14] fix type error in frontend --- frontend/src/routes/@[username]/PreferencesCheatsheet.svelte | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/routes/@[username]/PreferencesCheatsheet.svelte b/frontend/src/routes/@[username]/PreferencesCheatsheet.svelte index ac4200a..ebe56f1 100644 --- a/frontend/src/routes/@[username]/PreferencesCheatsheet.svelte +++ b/frontend/src/routes/@[username]/PreferencesCheatsheet.svelte @@ -1,5 +1,5 @@