mirror of
https://github.com/CompassConnections/Compass.git
synced 2026-05-09 15:44:55 -04:00
Trim trailing whitespaces in profile data
This commit is contained in:
@@ -1,14 +1,15 @@
|
||||
import { APIError, APIHandler } from 'api/helpers/endpoint'
|
||||
import { createSupabaseDirectClient } from 'shared/supabase/init'
|
||||
import { log, getUser } from 'shared/utils'
|
||||
import {APIError, APIHandler} from 'api/helpers/endpoint'
|
||||
import {createSupabaseDirectClient} from 'shared/supabase/init'
|
||||
import {getUser, log} from 'shared/utils'
|
||||
import {HOUR_MS, MINUTE_MS, sleep} from 'common/util/time'
|
||||
import { removePinnedUrlFromPhotoUrls } from 'shared/profiles/parse-photos'
|
||||
import { track } from 'shared/analytics'
|
||||
import { updateUser } from 'shared/supabase/users'
|
||||
import { tryCatch } from 'common/util/try-catch'
|
||||
import { insert } from 'shared/supabase/utils'
|
||||
import {removePinnedUrlFromPhotoUrls} from 'shared/profiles/parse-photos'
|
||||
import {track} from 'shared/analytics'
|
||||
import {updateUser} from 'shared/supabase/users'
|
||||
import {tryCatch} from 'common/util/try-catch'
|
||||
import {insert} from 'shared/supabase/utils'
|
||||
import {sendDiscordMessage} from "common/discord/core";
|
||||
import {jsonToMarkdown} from "common/md";
|
||||
import {trimStrings} from "common/parsing";
|
||||
|
||||
export const createProfile: APIHandler<'create-profile'> = async (body, auth) => {
|
||||
const pg = createSupabaseDirectClient()
|
||||
@@ -23,6 +24,8 @@ export const createProfile: APIHandler<'create-profile'> = async (body, auth) =>
|
||||
}
|
||||
|
||||
await removePinnedUrlFromPhotoUrls(body)
|
||||
trimStrings(body)
|
||||
|
||||
const user = await getUser(auth.uid)
|
||||
if (!user) throw new APIError(401, 'Your account was not found')
|
||||
if (user.createdTime > Date.now() - HOUR_MS) {
|
||||
|
||||
@@ -1,16 +1,18 @@
|
||||
import { APIError, APIHandler } from 'api/helpers/endpoint'
|
||||
import { removePinnedUrlFromPhotoUrls } from 'shared/profiles/parse-photos'
|
||||
import { createSupabaseDirectClient } from 'shared/supabase/init'
|
||||
import { updateUser } from 'shared/supabase/users'
|
||||
import { log } from 'shared/utils'
|
||||
import { tryCatch } from 'common/util/try-catch'
|
||||
import { update } from 'shared/supabase/utils'
|
||||
import { type Row } from 'common/supabase/utils'
|
||||
import {APIError, APIHandler} from 'api/helpers/endpoint'
|
||||
import {removePinnedUrlFromPhotoUrls} from 'shared/profiles/parse-photos'
|
||||
import {createSupabaseDirectClient} from 'shared/supabase/init'
|
||||
import {updateUser} from 'shared/supabase/users'
|
||||
import {log} from 'shared/utils'
|
||||
import {tryCatch} from 'common/util/try-catch'
|
||||
import {update} from 'shared/supabase/utils'
|
||||
import {type Row} from 'common/supabase/utils'
|
||||
import {trimStrings} from "common/parsing";
|
||||
|
||||
export const updateProfile: APIHandler<'update-profile'> = async (
|
||||
parsedBody,
|
||||
auth
|
||||
) => {
|
||||
trimStrings(parsedBody)
|
||||
log('Updating profile', parsedBody)
|
||||
const pg = createSupabaseDirectClient()
|
||||
|
||||
|
||||
@@ -1,3 +1,13 @@
|
||||
export const toKey = (str: string | number | boolean) => {
|
||||
return String(str).replace(/ /g, '_').toLowerCase()
|
||||
}
|
||||
|
||||
export function trimStrings<T extends Record<string, unknown | string>>(body: T): T {
|
||||
for (const key in body) {
|
||||
const value = (body[key] as unknown | string)
|
||||
if (typeof value === 'string') {
|
||||
body[key] = value.trim() as T[typeof key]
|
||||
}
|
||||
}
|
||||
return body
|
||||
}
|
||||
Reference in New Issue
Block a user