Skip to content

Commit

Permalink
fix types
Browse files Browse the repository at this point in the history
  • Loading branch information
arily committed Oct 26, 2023
1 parent 548f17d commit 79ca731
Show file tree
Hide file tree
Showing 13 changed files with 40 additions and 23 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -255,3 +255,5 @@ articles/*
!articles/fallbacks
!src/server/env
/env.ts

.generated
1 change: 0 additions & 1 deletion daisyui.themes.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* eslint-env node */
// import * as convert from 'color-convert'

// @ts-expect-error got nothing
import themes from 'daisyui/src/theming/themes'

// import type { HSL } from 'color-convert/conversions'
Expand Down
1 change: 1 addition & 0 deletions src/composables/useDynamicSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export default async function () {
client.save(v)
serverData.value = await app.$client.me.dynamicSettings.update.mutate(v)
}

return {
data,
unchanged,
Expand Down
2 changes: 1 addition & 1 deletion src/pages/admin/users/[id].vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function options<T extends Record<string, string>, TTr extends (key: keyof T, va
</script>

<template>
<div class="sm:grid sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-2">
<div v-if="detail" class="sm:grid sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-2">
<div class="form-control">
<label class="label">
<span class="label-text">ID</span>
Expand Down
2 changes: 1 addition & 1 deletion src/pages/article/edit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ fr-FR:
</i18n>

<template>
<section class="container pb-8 mx-auto custom-container lg:px-2">
<section v-if="articles" class="container pb-8 mx-auto custom-container lg:px-2">
<div class="flex">
<ul class="menu menu-xs bg-base-100 rounded-lg max-w-xs w-full">
<tree
Expand Down
4 changes: 2 additions & 2 deletions src/pages/me/relations.vue
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,11 @@ fr-FR:
</div>
</div>
</div>
<div v-if="haveUserAsTheirFriend.length" class="divider text-xl py-8">
<div v-if="haveUserAsTheirFriend?.length" class="divider text-xl py-8">
{{ t('you-may-also-wonder') }}
</div>

<template v-if="haveUserAsTheirFriend.length">
<template v-if="haveUserAsTheirFriend?.length">
<div class="alert">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" class="stroke-current shrink-0 w-6 h-6">
<path
Expand Down
2 changes: 1 addition & 1 deletion src/server/backend/$base/@define-setting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Lang } from '~/def'
import type { DynamicSettingStore, DynamicUserSetting } from '~/def/user'

export type ExtractSettingType<TSetting extends Record<string, DynamicUserSetting<any, any, any>>> = {
[K in keyof TSetting]: TSetting[K] extends DynamicUserSetting<infer R, any, any> ? R : never
[K in keyof TSetting]?: TSetting[K] extends DynamicUserSetting<infer R, any, any> ? R : never
}
export type ExtractSettingValidatorType<TSetting extends Record<string, DynamicUserSetting<any, any, any>>> = {
[K in keyof TSetting]: TSetting[K] extends DynamicUserSetting<infer R, any, any> ? ZodType<R> : never
Expand Down
9 changes: 7 additions & 2 deletions src/server/backend/$base/server/article/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,14 @@ export abstract class ArticleProvider {
}

static async getLocalSlugs(query?: string) {
return dirTree(relative('.', ArticleProvider.articles), { normalizePath: true }, (item, PATH, stats) => {
// path: string
// name: string
// children?: Prop[]
// expandLevel?: number
// level?: number
return pick(dirTree(relative('.', ArticleProvider.articles), { normalizePath: true }, (item, PATH, stats) => {
item.path = relative(config.article.location, item.path)
})
}), ['path', 'name', 'children'])
}

protected static async getLocalArticleData(opt: {
Expand Down
1 change: 1 addition & 0 deletions src/server/backend/$base/server/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ export abstract class UserProvider<Id> extends IdTransformable {

abstract changePassword(
user: { id: Id },
oldPasswordMD5: string,
newPasswordMD5: string
): PromiseLike<UserCompact<Id>>

Expand Down
1 change: 0 additions & 1 deletion src/server/backend/bancho.py/db-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export const userCompacts: Prisma.UserFindManyArgs = {
safeName: true,
country: true,
priv: true,
email: true,
},
} as const satisfies {
select: Record<DatabaseUserCompactFields, true>
Expand Down
2 changes: 1 addition & 1 deletion src/server/backend/bancho.py/dynamic-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const settings = {
label: 'api-key',
type: 'input',
disabled: true,
validator: z.string(),
validator: z.string().optional(),
locale: {
[Lang.enGB]: {
'api-key': 'API Key',
Expand Down
31 changes: 21 additions & 10 deletions src/server/backend/bancho.py/server/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { TRPCError } from '@trpc/server'

import { glob } from 'glob'
import imageType from 'image-type'
import type { Prisma, Stat } from 'prisma-client-bancho-py'
import { merge } from 'lodash-es'
import bcrypt from 'bcryptjs'
import type { Prisma, Stat } from 'prisma-client-bancho-py'
import { BanchoPyMode, BanchoPyScoreStatus } from '../enums'
import {
BPyMode,
Expand Down Expand Up @@ -131,9 +131,7 @@ class DBUserProvider extends Base<Id> implements Base<Id> {
) > 0
}

async getCompactById<
_Scope extends Scope = Scope.Public,
>({ id, scope }: { id: Id; scope?: _Scope }) {
async getCompactById({ id }: { id: Id }) {
/* optimized */
const user = await this.db.user.findFirstOrThrow({
where: {
Expand Down Expand Up @@ -512,11 +510,24 @@ WHERE s.userid = ${id}
}
}

async changePassword(user: UserCompact<Id>, newPasswordMD5: string) {
async changePassword(user: UserCompact<Id>, oldPasswordMD5: string, newPasswordMD5: string) {
const u = await this.db.user.findFirstOrThrow({
where: {
id: user.id,
},
})

if (!compare(oldPasswordMD5, u.pwBcrypt)) {
throw new TRPCError({
code: 'UNAUTHORIZED',
message: oldPasswordMismatch,
})
}

const pwBcrypt = await encryptBanchoPassword(newPasswordMD5)
const result = await this.db.user.update({
where: {
id: user.id,
id: u.id,
},
data: {
pwBcrypt,
Expand Down Expand Up @@ -711,15 +722,15 @@ WHERE s.userid = ${id}
async getDynamicSettings({ id }: { id: Id }) {
const user = await this.db.user.findFirstOrThrow({ where: { id } })
return {
apiKey: user.apiKey ?? '',
}
apiKey: user.apiKey || undefined,
} satisfies ServerSetting as ServerSetting
}

async setDynamicSettings(user: { id: number }, args: ServerSetting): Promise<ServerSetting> {
const result = await this.db.user.update({ where: { id: user.id }, data: { apiKey: args.apiKey } })
return {
apiKey: result.apiKey,
} as ServerSetting
apiKey: result.apiKey || undefined,
} satisfies ServerSetting
}
}

Expand Down
5 changes: 2 additions & 3 deletions src/store/dynamic-settings.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { defineStore } from 'pinia'
import type { z } from 'zod'
import { DynamicSettingStore } from '../def/user'
import { extractLocationSettings, extractSettingValidators } from '$base/@define-setting'
import { type ExtractSettingType, extractLocationSettings, extractSettingValidators } from '$base/@define-setting'

import { IntlPicker } from '$base/intl-picker'
import { settings } from '$active/dynamic-settings'

export const useClientDynamicSettings = defineStore('dynamic-client', () => {
const validator = extractSettingValidators(extractLocationSettings(DynamicSettingStore.Local, settings))
type T = z.infer<typeof validator>
type T = ExtractSettingType<typeof settings>
const data = ref<T>({
intlName: IntlPicker.Intl,
})
Expand Down

0 comments on commit 79ca731

Please sign in to comment.