Skip to content

Commit c4ee9a9

Browse files
committed
fix: script content gets replaced properly again
1 parent 944c258 commit c4ee9a9

File tree

86 files changed

+2088
-2585
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+2088
-2585
lines changed

.prettierrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"singleQuote": false,
44
"trailingComma": "none",
55
"semi": false,
6-
"printWidth": 100,
6+
"printWidth": 110,
77
"plugins": ["prettier-plugin-svelte", "prettier-plugin-tailwindcss"],
88
"overrides": [{ "files": "*.svelte", "options": { "parser": "svelte" } }],
99
"tailwindStylesheet": "./src/app.css"

src/app.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<body
1010
data-sveltekit-preload-data="hover"
1111
data-theme=""
12-
class="from-primary-50-950 to-surface-50-950 bg-radial-[at_0%_10%] to-30%"
12+
class="bg-radial-[at_0%_10%] from-primary-50-950 to-surface-50-950 to-30%"
1313
>
1414
<div style="display: contents">%sveltekit.body%</div>
1515
</body>

src/hooks.server.ts

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,24 @@ const redirects: Handle = async ({ event, resolve }) => {
1313
const path = event.url.pathname.slice(14)
1414
if (path === "") return resolve(event)
1515

16-
const searchParams =
17-
event.url.searchParams.toString() + "&path=" + encodeURI(path.replaceAll("_-_", "/"))
16+
const searchParams = event.url.searchParams.toString() + "&path=" + encodeURI(path.replaceAll("_-_", "/"))
1817

1918
return redirect(303, "/auth/callback?" + searchParams)
2019
}
2120
return resolve(event)
2221
}
2322

2423
const supabase: Handle = async ({ event, resolve }) => {
25-
event.locals.supabaseServer = createServerClient<Database>(
26-
PUBLIC_SUPABASE_URL,
27-
PUBLIC_SUPABASE_ANON_KEY,
28-
{
29-
cookies: {
30-
getAll: () => event.cookies.getAll(),
31-
setAll: (cookiesToSet) => {
32-
cookiesToSet.forEach(({ name, value, options }) => {
33-
event.cookies.set(name, value, { ...options, path: "/" })
34-
})
35-
}
24+
event.locals.supabaseServer = createServerClient<Database>(PUBLIC_SUPABASE_URL, PUBLIC_SUPABASE_ANON_KEY, {
25+
cookies: {
26+
getAll: () => event.cookies.getAll(),
27+
setAll: (cookiesToSet) => {
28+
cookiesToSet.forEach(({ name, value, options }) => {
29+
event.cookies.set(name, value, { ...options, path: "/" })
30+
})
3631
}
3732
}
38-
)
33+
})
3934

4035
event.locals.launcherSupabase = createServerClient<Database>(
4136
PUBLIC_SUPABASE_URL,
@@ -172,8 +167,7 @@ const theme: Handle = async ({ event, resolve }) => {
172167
}
173168

174169
return await resolve(event, {
175-
transformPageChunk: ({ html }) =>
176-
html.replace('data-theme=""', `data-theme="${cookieTheme ?? "wasp"}"`)
170+
transformPageChunk: ({ html }) => html.replace('data-theme=""', `data-theme="${cookieTheme ?? "wasp"}"`)
177171
})
178172
}
179173

@@ -186,11 +180,4 @@ const performanceCheck: Handle = async ({ event, resolve }) => {
186180
return response
187181
}
188182

189-
export const handle: Handle = sequence(
190-
redirects,
191-
darkMode,
192-
theme,
193-
supabase,
194-
authGuard,
195-
performanceCheck
196-
)
183+
export const handle: Handle = sequence(redirects, darkMode, theme, supabase, authGuard, performanceCheck)

src/lib/client/schemas.ts

Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ const content = z
2020
message: "Must be at least 10 characters long"
2121
})
2222
.refine((str) => str === null || str === "" || str.includes(" "), {
23-
message:
24-
"You have no spaces, this is supposed to be at least a couple of words, ideally a few sentences."
23+
message: "You have no spaces, this is supposed to be at least a couple of words, ideally a few sentences."
2524
})
2625

2726
const categoryKeys = Object.keys(scriptCategories) as TScriptCategories
@@ -41,18 +40,12 @@ export const baseScriptSchema = z.object({
4140
.regex(/^[a-fA-F0-9]+$/, "Must be a valid hexadecimal string"),
4241
wasplib: z
4342
.string()
44-
.regex(
45-
/^\d{4}\.\d{2}\.\d{2}-[a-fA-F0-9]{7}$/,
46-
"Must match format YYYY.MM.DD-HEX with valid hex"
47-
),
43+
.regex(/^\d{4}\.\d{2}\.\d{2}-[a-fA-F0-9]{7}$/, "Must match format YYYY.MM.DD-HEX with valid hex"),
4844
xp_min: z
4945
.number()
5046
.int("Only whole numbers are allowed.")
5147
.gte(0, "There's no way to lose experience in OSRS."),
52-
xp_max: z
53-
.number()
54-
.int("Only whole numbers are allowed.")
55-
.max(60000, "That exceeds the reasonable limit."),
48+
xp_max: z.number().int("Only whole numbers are allowed.").max(60000, "That exceeds the reasonable limit."),
5649
gp_min: z
5750
.number()
5851
.int("Only whole numbers are allowed.")
@@ -97,10 +90,7 @@ export const addScriptClientSchema = baseScriptSchema
9790
(schema) => schema.xp_min <= schema.xp_max,
9891
"Minimum experience cannot exceed the maximum experience."
9992
)
100-
.refine(
101-
(schema) => schema.gp_min <= schema.gp_max,
102-
"Minimum gold cannot exceed the maximum gold."
103-
)
93+
.refine((schema) => schema.gp_min <= schema.gp_max, "Minimum gold cannot exceed the maximum gold.")
10494

10595
export type AddScriptSchema = z.infer<typeof addScriptClientSchema>
10696

@@ -124,10 +114,7 @@ export const updateScriptClientSchema = baseScriptSchema
124114
(schema) => schema.xp_min <= schema.xp_max,
125115
"Minimum experience cannot exceed the maximum experience."
126116
)
127-
.refine(
128-
(schema) => schema.gp_min <= schema.gp_max,
129-
"Minimum gold cannot exceed the maximum gold."
130-
)
117+
.refine((schema) => schema.gp_min <= schema.gp_max, "Minimum gold cannot exceed the maximum gold.")
131118

132119
export type UpdateScriptSchema = z.infer<typeof updateScriptClientSchema>
133120

@@ -163,20 +150,14 @@ export const profileSchema = z.object({
163150

164151
export const scripterSchema = z.object({
165152
id: z.string().uuid("ID must be a valid UUIDv4."),
166-
realname: z
167-
.string()
168-
.min(2, "If your name really has less than 2 characters contact Torwent.")
169-
.nullable(),
153+
realname: z.string().min(2, "If your name really has less than 2 characters contact Torwent.").nullable(),
170154
description: z
171155
.string()
172156
.min(6, "Must be more than 6 characters long.")
173157
.max(32, "Must be less than 32 characters long.")
174158
.includes(" ", { message: "This should be a sentence or at least a couple of words." })
175159
.nullable(),
176-
github: z
177-
.string()
178-
.startsWith("https://github.com/", "This should be a github user profile.")
179-
.nullable(),
160+
github: z.string().startsWith("https://github.com/", "This should be a github user profile.").nullable(),
180161
paypal: z
181162
.string()
182163
.length(
@@ -236,10 +217,7 @@ export const checkoutSchema = z.object({
236217
})
237218

238219
const newPriceSchema = z.object({
239-
amount: z
240-
.number()
241-
.gte(0, "Amount has to be a positive value.")
242-
.lte(200, "Amount can't be more than 200€."),
220+
amount: z.number().gte(0, "Amount has to be a positive value.").lte(200, "Amount can't be more than 200€."),
243221
interval: z.string().min(4).max(5).regex(new RegExp("week|month|year")),
244222
currency: z.string().length(3).regex(new RegExp("eur"))
245223
})

src/lib/client/supabase.ts

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
import type {
2-
ProfileRole,
3-
Script,
4-
Scripter,
5-
SimpleScripter,
6-
StatsTotal
7-
} from "$lib/types/collection"
1+
import type { ProfileRole, Script, Scripter, SimpleScripter, StatsTotal } from "$lib/types/collection"
82
import type { Database } from "$lib/types/supabase"
93
import { UUID_V4_REGEX, formatError } from "$lib/utils"
104
import type { SupabaseClient } from "@supabase/supabase-js"
@@ -88,11 +82,7 @@ export async function getStatsTotal(supabase: SupabaseClient) {
8882
return data
8983
}
9084

91-
export function canEdit(
92-
id: string | null | undefined,
93-
role: ProfileRole,
94-
author: string | null | undefined
95-
) {
85+
export function canEdit(id: string | null | undefined, role: ProfileRole, author: string | null | undefined) {
9686
if (!id || !role || !author) return false
9787
if (["administrator", "moderator"].includes(role)) return true
9888
return id === author
@@ -187,11 +177,7 @@ export async function fetchScriptByID(supabase: SupabaseClient<Database>, id: st
187177
return data
188178
}
189179

190-
export async function scriptExists(
191-
supabase: SupabaseClient,
192-
slug: string,
193-
isUUID: boolean | null = null
194-
) {
180+
export async function scriptExists(supabase: SupabaseClient, slug: string, isUUID: boolean | null = null) {
195181
if (scripts.has(slug)) return true
196182

197183
console.log("💥 Fetching script " + slug)
@@ -212,11 +198,7 @@ export async function scriptExists(
212198
return true
213199
}
214200

215-
export async function canDownload(
216-
supabase: SupabaseClient,
217-
role: ProfileRole,
218-
script_id: string | null
219-
) {
201+
export async function canDownload(supabase: SupabaseClient, role: ProfileRole, script_id: string | null) {
220202
if (!script_id) return false
221203
if (role && ["administrator", "moderator", "tester"].includes(role)) return true
222204

@@ -228,12 +210,7 @@ export async function canDownload(
228210
return data ?? false
229211
}
230212

231-
export async function getSignedURL(
232-
supabase: SupabaseClient,
233-
bucket: string,
234-
path: string,
235-
file: string
236-
) {
213+
export async function getSignedURL(supabase: SupabaseClient, bucket: string, path: string, file: string) {
237214
path += "/" + file
238215

239216
const { data, error: err } = await supabase.storage.from(bucket).createSignedUrl(path, 10)

src/lib/client/utils.ts

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@ import type { Script, ScriptLimits, ScriptPublic } from "$lib/types/collection"
44
import { ACCEPTED_IMAGE_TYPES, formatNumber } from "$lib/utils"
55
import { error } from "@sveltejs/kit"
66

7-
export async function replaceQuery(
8-
url: URL,
9-
values: Record<string, string>,
10-
noscroll: boolean = true
11-
) {
7+
export async function replaceQuery(url: URL, values: Record<string, string>, noscroll: boolean = true) {
128
if (!browser) return
139

1410
const { origin, pathname, searchParams } = url
@@ -73,10 +69,10 @@ export function getScriptContent(
7369
updated_at: new Date(Date.now()).toLocaleString(locale),
7470
revision_date: new Date(Date.now()).toLocaleString(locale, date),
7571
revision_time: new Date(Date.now()).toLocaleString(locale, time),
76-
min_xp: formatNumber(Number(limits.xp_min * 12)),
77-
max_xp: formatNumber(Number(limits.xp_max * 12)),
78-
min_gp: formatNumber(Number(limits.gp_min * 12)),
79-
max_gp: formatNumber(Number(limits.gp_max * 12))
72+
xp_min: formatNumber(Number(limits.xp_min * 12)),
73+
xp_max: formatNumber(Number(limits.xp_max * 12)),
74+
gp_min: formatNumber(Number(limits.gp_min * 12)),
75+
gp_max: formatNumber(Number(limits.gp_max * 12))
8076
}
8177

8278
const result = script.content.replace(/\{\$([^{}\s$]+)\}/g, (match, placeholder) => {
@@ -87,7 +83,7 @@ export function getScriptContent(
8783
return result
8884
}
8985

90-
export function replaceScriptContent(script: Script, locale: string = "pt-PT") {
86+
export function replaceScriptContent(script: Script, limits: ScriptLimits, locale: string = "pt-PT") {
9187
const date: Intl.DateTimeFormatOptions = {
9288
day: "2-digit",
9389
month: "2-digit",
@@ -109,7 +105,11 @@ export function replaceScriptContent(script: Script, locale: string = "pt-PT") {
109105
revision: script.protected.revision.toString(),
110106
updated_at: new Date(script.protected.updated_at).toLocaleString(locale),
111107
revision_date: new Date(script.protected.updated_at).toLocaleString(locale, date),
112-
revision_time: new Date(script.protected.updated_at).toLocaleString(locale, time)
108+
revision_time: new Date(script.protected.updated_at).toLocaleString(locale, time),
109+
xp_min: formatNumber(Number(limits.xp_min * 12)),
110+
xp_max: formatNumber(Number(limits.xp_max * 12)),
111+
gp_min: formatNumber(Number(limits.gp_min * 12)),
112+
gp_max: formatNumber(Number(limits.gp_max * 12))
113113
}
114114

115115
const result = script.content.replace(/\{\$([^{}\s$]+)\}/g, (match, placeholder) => {
@@ -120,11 +120,7 @@ export function replaceScriptContent(script: Script, locale: string = "pt-PT") {
120120
return result
121121
}
122122

123-
export async function checkClientImageDimensions(
124-
file: File,
125-
w: number,
126-
h: number
127-
): Promise<boolean> {
123+
export async function checkClientImageDimensions(file: File, w: number, h: number): Promise<boolean> {
128124
if (!browser) return false
129125
if (!ACCEPTED_IMAGE_TYPES.includes(file.type)) return false
130126

src/lib/components/Head.svelte

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
<script lang="ts">
22
import { page } from "$app/state"
33
4-
let {
5-
title,
6-
description,
7-
keywords = undefined,
8-
author = "Torwent",
9-
img = "/favicon.png"
10-
} = $props()
4+
let { title, description, keywords = undefined, author = "Torwent", img = "/favicon.png" } = $props()
115
126
const basekeywords =
137
"OldSchool, RuneScape, OSRS, 2007, Color, Colour, Bot, Botting, Wasp, Scripts, WaspScripts, Simba, Open, Source, OpenSource"

src/lib/components/NewScriptCard.svelte

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,30 +31,25 @@
3131
</script>
3232

3333
<div
34-
class="card card-hover preset-filled-surface-200-800 hover:preset-outlined flex h-96 w-64 flex-col shadow-sm"
34+
class="flex h-96 w-64 flex-col card preset-filled-surface-200-800 shadow-sm card-hover hover:preset-outlined"
3535
>
3636
<header class="m-1">
3737
<img src={imgLink} alt="Script cover" class="rounded-md contain-content" loading="lazy" />
3838
</header>
3939
<section class="m-2 flex h-full flex-col">
4040
<header class="flex h-fit flex-col">
41-
<span class="text-primary-600 dark:text-primary-500 font-semibold whitespace-break-spaces">
41+
<span class="font-semibold whitespace-break-spaces text-primary-600 dark:text-primary-500">
4242
{script.title}
4343
</span>
44-
<span class="text-primary-600 dark:text-secondary-500 text-xs drop-shadow">
44+
<span class="text-xs text-primary-600 drop-shadow dark:text-secondary-500">
4545
by
46-
<a
47-
href="/scripters/{encodeSEO(username.normalize('NFKC'))}"
48-
class="hover:preset-tonal-secondary"
49-
>
46+
<a href="/scripters/{encodeSEO(username.normalize('NFKC'))}" class="hover:preset-tonal-secondary">
5047
{username}
5148
</a>
5249
{#if !script.published}<small class="text-error-500">Unpublished</small>{/if}
5350
</span>
5451
</header>
55-
<article
56-
class="text-surface-600 dark:text-surface-300 my-4 h-full overflow-y-auto text-sm break-words"
57-
>
52+
<article class="my-4 h-full overflow-y-auto text-sm break-words text-surface-600 dark:text-surface-300">
5853
{cropString(script.description, 80)}
5954
</article>
6055
</section>

src/lib/components/Paginator.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
<select
2929
name="size"
3030
id="size"
31-
class="select mx-auto max-w-[150px] md:mx-0"
31+
class="mx-auto select max-w-[150px] md:mx-0"
3232
bind:value={pageSize}
3333
onchange={() => replaceQuery(page.url, { amount: pageSize.toString() })}
3434
>

0 commit comments

Comments
 (0)