getThumbUrl

This commit is contained in:
Untone 2024-07-13 15:25:25 +03:00
parent 7c9c155f5b
commit 35c5a0ebcf
15 changed files with 28 additions and 62 deletions

View File

@ -12,7 +12,7 @@ import { DEFAULT_HEADER_OFFSET, useUI } from '~/context/ui'
import type { Author, Maybe, Shout, Topic } from '~/graphql/schema/core.gen' import type { Author, Maybe, Shout, Topic } from '~/graphql/schema/core.gen'
import { processPrepositions } from '~/intl/prepositions' import { processPrepositions } from '~/intl/prepositions'
import { isCyrillic } from '~/intl/translate' import { isCyrillic } from '~/intl/translate'
import { getImageUrl } from '~/lib/getImageUrl' import { getImageUrl } from '~/lib/getThumbUrl'
import { MediaItem } from '~/types/mediaitem' import { MediaItem } from '~/types/mediaitem'
import { capitalize } from '~/utils/capitalize' import { capitalize } from '~/utils/capitalize'
import { AuthorBadge } from '../Author/AuthorBadge' import { AuthorBadge } from '../Author/AuthorBadge'

View File

@ -1,7 +1,7 @@
import { clsx } from 'clsx' import { clsx } from 'clsx'
import { Show, createMemo } from 'solid-js' import { Show, createMemo } from 'solid-js'
import { getImageUrl } from '~/lib/getImageUrl' import { getImageUrl } from '~/lib/getThumbUrl'
import './DialogCard.module.scss' import './DialogCard.module.scss'
import styles from './DialogAvatar.module.scss' import styles from './DialogAvatar.module.scss'

View File

@ -6,7 +6,7 @@ import { useFollowing } from '~/context/following'
import { useLocalize } from '~/context/localize' import { useLocalize } from '~/context/localize'
import { useSession } from '~/context/session' import { useSession } from '~/context/session'
import { FollowingEntity, Topic } from '~/graphql/schema/core.gen' import { FollowingEntity, Topic } from '~/graphql/schema/core.gen'
import { getImageUrl } from '~/lib/getImageUrl' import { getImageUrl } from '~/lib/getThumbUrl'
import { mediaMatches } from '~/lib/mediaQuery' import { mediaMatches } from '~/lib/mediaQuery'
import { capitalize } from '~/utils/capitalize' import { capitalize } from '~/utils/capitalize'
import styles from './TopicBadge.module.scss' import styles from './TopicBadge.module.scss'

View File

@ -25,7 +25,7 @@ import { useLocalize } from '~/context/localize'
import getMyShoutQuery from '~/graphql/query/core/article-my' import getMyShoutQuery from '~/graphql/query/core/article-my'
import type { Shout, Topic } from '~/graphql/schema/core.gen' import type { Shout, Topic } from '~/graphql/schema/core.gen'
import { slugify } from '~/intl/translit' import { slugify } from '~/intl/translit'
import { getImageUrl } from '~/lib/getImageUrl' import { getImageUrl } from '~/lib/getThumbUrl'
import { isDesktop } from '~/lib/mediaQuery' import { isDesktop } from '~/lib/mediaQuery'
import { LayoutType } from '~/types/common' import { LayoutType } from '~/types/common'
import { MediaItem } from '~/types/mediaitem' import { MediaItem } from '~/types/mediaitem'

View File

@ -19,7 +19,7 @@ import { useProfile } from '~/context/profile'
import { useSession } from '~/context/session' import { useSession } from '~/context/session'
import { useSnackbar, useUI } from '~/context/ui' import { useSnackbar, useUI } from '~/context/ui'
import { InputMaybe, ProfileInput } from '~/graphql/schema/core.gen' import { InputMaybe, ProfileInput } from '~/graphql/schema/core.gen'
import { getImageUrl } from '~/lib/getImageUrl' import { getImageUrl } from '~/lib/getThumbUrl'
import { handleImageUpload } from '~/lib/handleImageUpload' import { handleImageUpload } from '~/lib/handleImageUpload'
import { profileSocialLinks } from '~/lib/profileSocialLinks' import { profileSocialLinks } from '~/lib/profileSocialLinks'
import { clone } from '~/utils/clone' import { clone } from '~/utils/clone'

View File

@ -3,7 +3,7 @@ import type { JSX } from 'solid-js'
import { Link } from '@solidjs/meta' import { Link } from '@solidjs/meta'
import { splitProps } from 'solid-js' import { splitProps } from 'solid-js'
import { getImageUrl } from '~/lib/getImageUrl' import { getImageUrl } from '~/lib/getThumbUrl'
type Props = JSX.ImgHTMLAttributes<HTMLImageElement> & { type Props = JSX.ImgHTMLAttributes<HTMLImageElement> & {
width: number width: number

View File

@ -1,7 +1,7 @@
import { clsx } from 'clsx' import { clsx } from 'clsx'
import { Show, createEffect, createMemo, createSignal, on, onCleanup } from 'solid-js' import { Show, createEffect, createMemo, createSignal, on, onCleanup } from 'solid-js'
import { getImageUrl } from '~/lib/getImageUrl' import { getImageUrl } from '~/lib/getThumbUrl'
import { useEscKeyDownHandler } from '~/lib/useEscKeyDownHandler' import { useEscKeyDownHandler } from '~/lib/useEscKeyDownHandler'
import { Icon } from '../Icon' import { Icon } from '../Icon'

View File

@ -7,7 +7,7 @@ import { useLocalize } from '~/context/localize'
import { Shout } from '~/graphql/schema/core.gen' import { Shout } from '~/graphql/schema/core.gen'
import enKeywords from '~/intl/locales/en/keywords.json' import enKeywords from '~/intl/locales/en/keywords.json'
import ruKeywords from '~/intl/locales/ru/keywords.json' import ruKeywords from '~/intl/locales/ru/keywords.json'
import { getImageUrl, getOpenGraphImageUrl } from '~/lib/getImageUrl' import { getImageUrl, getOpenGraphImageUrl } from '~/lib/getThumbUrl'
import { descFromBody } from '~/utils/meta' import { descFromBody } from '~/utils/meta'
import { FooterView } from '../Discours/Footer' import { FooterView } from '../Discours/Footer'
import { Header } from '../Nav/Header' import { Header } from '../Nav/Header'

View File

@ -7,7 +7,7 @@ import { Manipulation, Navigation, Pagination } from 'swiper/modules'
import { useLocalize } from '~/context/localize' import { useLocalize } from '~/context/localize'
import { useSnackbar } from '~/context/ui' import { useSnackbar } from '~/context/ui'
import { composeMediaItems } from '~/lib/composeMediaItems' import { composeMediaItems } from '~/lib/composeMediaItems'
import { getImageUrl } from '~/lib/getImageUrl' import { getImageUrl } from '~/lib/getThumbUrl'
import { handleImageUpload } from '~/lib/handleImageUpload' import { handleImageUpload } from '~/lib/handleImageUpload'
import { validateUploads } from '~/lib/validateUploads' import { validateUploads } from '~/lib/validateUploads'
import { DropArea } from '../DropArea' import { DropArea } from '../DropArea'

View File

@ -4,7 +4,7 @@ import SwiperCore from 'swiper'
import { HashNavigation, Manipulation, Navigation, Pagination } from 'swiper/modules' import { HashNavigation, Manipulation, Navigation, Pagination } from 'swiper/modules'
import { throttle } from 'throttle-debounce' import { throttle } from 'throttle-debounce'
import { getImageUrl } from '~/lib/getImageUrl' import { getImageUrl } from '~/lib/getThumbUrl'
import { MediaItem } from '~/types/mediaitem' import { MediaItem } from '~/types/mediaitem'
import { Icon } from '../Icon' import { Icon } from '../Icon'
import { Image } from '../Image' import { Image } from '../Image'

View File

@ -8,12 +8,6 @@ const URL_CONFIG = {
productionFolder: 'production/' productionFolder: 'production/'
} }
const AUDIO_EXTENSIONS = new Set(['wav', 'mp3', 'ogg', 'aif', 'flac'])
const isAudioFile = (filename: string): boolean => {
const extension = filename.split('.').pop()?.toLowerCase()
return AUDIO_EXTENSIONS.has(extension ?? '')
}
const getLastSegment = (url: string): string => url.toLowerCase().split('/').pop() || '' const getLastSegment = (url: string): string => url.toLowerCase().split('/').pop() || ''
const buildSizePart = (width?: number, height?: number, includeSize = true): string => { const buildSizePart = (width?: number, height?: number, includeSize = true): string => {
@ -31,13 +25,21 @@ export const getImageUrl = (
return src return src
} }
const filename = getLastSegment(src) const filename = getLastSegment(src)
const base = isAudioFile(filename) ? URL_CONFIG.cdnUrl : URL_CONFIG.thumborUrl
const suffix = options.noSizeUrlPart ? '' : buildSizePart(options.width, options.height) const suffix = options.noSizeUrlPart ? '' : buildSizePart(options.width, options.height)
const subfolder = isAudioFile(filename) ? URL_CONFIG.audioSubfolder : URL_CONFIG.imageSubfolder const base = URL_CONFIG.thumborUrl
const subfolder = URL_CONFIG.imageSubfolder
return `${base}${suffix}${URL_CONFIG.productionFolder}${subfolder}/${filename}` return `${base}${suffix}${URL_CONFIG.productionFolder}${subfolder}/${filename}`
} }
export const getAudioUrl = (src: string) => {
const filename = getLastSegment(src)
const base = URL_CONFIG.cdnUrl
const subfolder = URL_CONFIG.audioSubfolder
const prodfolder = URL_CONFIG.productionFolder
return `${base}${prodfolder}${subfolder}/${filename}`
}
export const getOpenGraphImageUrl = ( export const getOpenGraphImageUrl = (
src: string, src: string,
options: { options: {

View File

@ -1,42 +0,0 @@
import type { Author, Shout, Topic } from '~/graphql/schema/core.gen'
export const groupByName = (arr: Author[]) => {
return arr.reduce(
(acc: { [key: string]: Author[] }, a: Author) => {
let c =
a?.name
?.replaceAll(/[^\d A-Za-zА-я]/g, '')
.split(' ')
.pop()
?.slice(0, 1)
.toUpperCase() || ''
if (c) {
if (/[^А-я]/.test(c)) c = 'A-Z'
else if (!acc[c]) acc[c] = []
acc[c].push(a)
}
return acc
},
{
'A-Z': []
}
)
}
export const groupByTitle = (arr: (Shout | Topic)[]) => {
return arr.reduce(
(acc: { [key: string]: (Topic | Shout)[] }, tt: Topic | Shout) => {
let c = (tt.title || '')
.replaceAll(/[^\d A-Za-zА-я]/g, '')
.slice(0, 1)
.toUpperCase()
if (/[^А-я]/.test(c)) c = 'A-Z'
else if (!acc[c]) acc[c] = []
acc[c].push(tt)
return acc
},
{
'A-Z': []
}
)
}

View File

@ -2,6 +2,12 @@ import { UploadFile } from '@solid-primitives/upload'
export const imageExtensions = new Set(['jpg', 'jpeg', 'png', 'gif', 'bmp']) export const imageExtensions = new Set(['jpg', 'jpeg', 'png', 'gif', 'bmp'])
export const docExtensions = new Set(['doc', 'docx', 'pdf', 'txt']) export const docExtensions = new Set(['doc', 'docx', 'pdf', 'txt'])
export const audioExtensions = new Set(['wav', 'mp3', 'ogg', 'aif', 'flac'])
export const isAudioFilename = (filename: string): boolean => {
const extension = filename.split('.').pop()?.toLowerCase()
return audioExtensions.has(extension || '')
}
export const validateUploads = (fileType: string, files: UploadFile[]): boolean => { export const validateUploads = (fileType: string, files: UploadFile[]): boolean => {
for (const file of files) { for (const file of files) {

View File

@ -15,7 +15,7 @@ import {
Shout, Shout,
Topic Topic
} from '~/graphql/schema/core.gen' } from '~/graphql/schema/core.gen'
import { getImageUrl } from '~/lib/getImageUrl' import { getImageUrl } from '~/lib/getThumbUrl'
import { SHOUTS_PER_PAGE } from '../../(main)' import { SHOUTS_PER_PAGE } from '../../(main)'
const fetchAuthorShouts = async (slug: string, offset?: number) => { const fetchAuthorShouts = async (slug: string, offset?: number) => {

View File

@ -9,7 +9,7 @@ import { useLocalize } from '~/context/localize'
import { useTopics } from '~/context/topics' import { useTopics } from '~/context/topics'
import { loadShouts, loadTopics } from '~/graphql/api/public' import { loadShouts, loadTopics } from '~/graphql/api/public'
import { Author, LoadShoutsOptions, Shout, Topic } from '~/graphql/schema/core.gen' import { Author, LoadShoutsOptions, Shout, Topic } from '~/graphql/schema/core.gen'
import { getImageUrl } from '~/lib/getImageUrl' import { getImageUrl } from '~/lib/getThumbUrl'
import { descFromBody } from '~/utils/meta' import { descFromBody } from '~/utils/meta'
import { SHOUTS_PER_PAGE } from '../../(main)' import { SHOUTS_PER_PAGE } from '../../(main)'