Skip to content

Commit 92d4d01

Browse files
committed
.
1 parent b1c266e commit 92d4d01

File tree

13 files changed

+88
-433
lines changed

13 files changed

+88
-433
lines changed

src/index.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { AssetHandler } from './routes/asset'
66
import { GameHandler } from './routes/game'
77
import { CategoryHandler } from './routes/category'
88
import { TagHandler } from './routes/tag'
9-
import { AuthHandler } from './routes/auth'
109
import { UserHandler } from './routes/user'
1110
import { apiReference } from '@scalar/hono-api-reference'
1211
import { rateLimiter } from 'hono-rate-limiter'
@@ -22,7 +21,7 @@ app.use(
2221
// 'http://localhost:8787',
2322
// 'http://localhost:3000',
2423
'https://skowt.cc',
25-
'https://staging.skowt.cc',
24+
// 'https://staging.skowt.cc',
2625
],
2726
allowMethods: ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS'],
2827
allowHeaders: ['Content-Type', 'Authorization', 'Accept', 'X-Requested-With'],
@@ -50,7 +49,6 @@ app.route('/game', GameHandler)
5049
app.route('/category', CategoryHandler)
5150
app.route('/tag', TagHandler)
5251
app.route('/user', UserHandler)
53-
app.route('/personal', AuthHandler)
5452

5553
app.get('/', c => {
5654
return c.json({ message: 'api is up!', swagger: '/swagger', reference: '/reference' })

src/lib/auth/auth.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { betterAuth } from 'better-auth'
22
import { drizzleAdapter } from 'better-auth/adapters/drizzle'
3+
import { name } from 'drizzle-orm'
34
import { getConnection } from '~/lib/db/connection'
45
import * as schema from '~/lib/db/schema'
56
import { Env } from '~/lib/handler'
@@ -23,14 +24,21 @@ export function createAuth(env: Env) {
2324
// 'http://localhost:8787',
2425
// 'http://localhost:3000',
2526
'https://skowt.cc',
26-
'https://staging.skowt.cc',
27+
// 'https://staging.skowt.cc',
2728
],
2829
secret: env.BETTER_AUTH_SECRET,
2930
baseURL: env.BETTER_AUTH_URL,
3031
socialProviders: {
3132
discord: {
33+
overrideUserInfoOnSignIn: true,
3234
clientId: env.DISCORD_CLIENT_ID as string,
3335
clientSecret: env.DISCORD_CLIENT_SECRET as string,
36+
mapProfileToUser: async (profile) => {
37+
return {
38+
name: profile.username,
39+
displayName: profile.global_name || profile.username,
40+
};
41+
},
3442
},
3543
},
3644
emailAndPassword: {

src/routes/asset/search.ts

Lines changed: 17 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -55,29 +55,17 @@ const querySchema = z.object({
5555
},
5656
example: 'character-sheets,splash-art',
5757
}),
58-
page: z
58+
offset: z
5959
.string()
6060
.optional()
6161
.openapi({
6262
param: {
63-
description: 'Page number for pagination (starts at 1).',
63+
description: 'Number of results to skip for pagination (starts at 0).',
6464
in: 'query',
65-
name: 'page',
65+
name: 'offset',
6666
required: false,
6767
},
68-
example: '1',
69-
}),
70-
limit: z
71-
.string()
72-
.optional()
73-
.openapi({
74-
param: {
75-
description: 'Number of results per page (max 50).',
76-
in: 'query',
77-
name: 'limit',
78-
required: false,
79-
},
80-
example: '20',
68+
example: '0',
8169
}),
8270
sortBy: z
8371
.enum(['viewCount', 'downloadCount', 'uploadDate', 'name'])
@@ -139,12 +127,8 @@ const responseSchema = z.object({
139127
}),
140128
),
141129
pagination: z.object({
142-
page: z.number(),
143-
limit: z.number(),
144-
total: z.number(),
145-
totalPages: z.number(),
130+
offset: z.number(),
146131
hasNext: z.boolean(),
147-
hasPrev: z.boolean(),
148132
}),
149133
})
150134

@@ -174,7 +158,7 @@ export const AssetSearchRoute = (handler: AppHandler) => {
174158
handler.use(
175159
'/search',
176160
cache({
177-
cacheName: 'asset-search',
161+
cacheName: 'asset-search-all',
178162
cacheControl: 'max-age=600, s-maxage=600',
179163
}),
180164
)
@@ -184,17 +168,15 @@ export const AssetSearchRoute = (handler: AppHandler) => {
184168

185169
const { drizzle } = getConnection(ctx.env)
186170

187-
const page = query.page ? parseInt(query.page) : 1
188-
const limit = query.limit ? Math.min(parseInt(query.limit), 50) : 20
189-
const offset = (page - 1) * limit
171+
const offset = query.offset ? parseInt(query.offset) : 0
190172
const sortBy = query.sortBy || 'uploadDate'
191173
const sortOrder = query.sortOrder || 'desc'
192174

193-
if (page < 1) {
175+
if (offset < 0) {
194176
return ctx.json(
195177
{
196178
success: false,
197-
message: 'Page must be 1 or greater',
179+
message: 'Offset must be 0 or greater',
198180
},
199181
400,
200182
)
@@ -296,17 +278,12 @@ export const AssetSearchRoute = (handler: AppHandler) => {
296278
.where(and(conditions.length > 0 ? and(...conditions) : undefined, eq(asset.status, 'approved')))
297279
.orderBy(sortDirection(sortColumn))
298280

299-
const countQuery = drizzle
300-
.select({ count: sql<number>`COUNT(*)` })
301-
.from(asset)
302-
.where(and(conditions.length > 0 ? and(...conditions) : undefined, eq(asset.status, 'approved')))
303-
304-
const [assets, countResult] = await Promise.all([baseQuery.limit(limit).offset(offset), countQuery])
281+
const assets = await baseQuery.limit(21).offset(offset)
305282

306-
const total = countResult[0]?.count || 0
307-
const totalPages = Math.ceil(total / limit)
283+
const hasNext = assets.length > 20
284+
const finalAssets = hasNext ? assets.slice(0, 20) : assets
308285

309-
const assetIds = assets.map(a => a.id)
286+
const assetIds = finalAssets.map(a => a.id)
310287
const assetTags =
311288
assetIds.length > 0
312289
? await drizzle
@@ -337,7 +314,7 @@ export const AssetSearchRoute = (handler: AppHandler) => {
337314
{} as Record<string, any[]>,
338315
)
339316

340-
const uploaderIds = assets.map(a => a.uploadedBy)
317+
const uploaderIds = finalAssets.map(a => a.uploadedBy)
341318
const uploaders =
342319
uploaderIds.length > 0
343320
? await drizzle
@@ -351,7 +328,7 @@ export const AssetSearchRoute = (handler: AppHandler) => {
351328
: []
352329
const uploaderMap = Object.fromEntries(uploaders.map(u => [u.id, u]))
353330

354-
const formattedAssets = assets.map(asset => {
331+
const formattedAssets = finalAssets.map(asset => {
355332
const gameInfo = gameMap[asset.gameId]
356333
const categoryInfo = categoryMap[asset.categoryId]
357334

@@ -372,12 +349,8 @@ export const AssetSearchRoute = (handler: AppHandler) => {
372349
success: true,
373350
assets: formattedAssets,
374351
pagination: {
375-
page,
376-
limit,
377-
total,
378-
totalPages,
379-
hasNext: page < totalPages,
380-
hasPrev: page > 1,
352+
offset,
353+
hasNext,
381354
},
382355
},
383356
200,

src/routes/auth/index.ts

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/routes/auth/logout.ts

Lines changed: 0 additions & 73 deletions
This file was deleted.

src/routes/auth/profile.ts

Lines changed: 0 additions & 118 deletions
This file was deleted.

0 commit comments

Comments
 (0)