mirror of
https://github.com/jeffvli/sonixd.git
synced 2026-05-19 06:08:59 -04:00
Add utils
This commit is contained in:
@@ -95,6 +95,7 @@ export type OffsetPagination = {
|
||||
};
|
||||
|
||||
export type PaginationResponse = {
|
||||
currentPage: number;
|
||||
nextPage: string;
|
||||
prevPage: string;
|
||||
startIndex: number;
|
||||
@@ -108,6 +109,7 @@ export type SuccessResponse = {
|
||||
|
||||
export type PaginationItems = {
|
||||
limit: number;
|
||||
page: number;
|
||||
startIndex: number;
|
||||
totalEntries: number;
|
||||
url: string;
|
||||
|
||||
19
src/server/utils/get-image-url.ts
Normal file
19
src/server/utils/get-image-url.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
export const getImageUrl = (
|
||||
serverType: string,
|
||||
baseUrl: string,
|
||||
imageId: string,
|
||||
token?: string
|
||||
) => {
|
||||
if (serverType === 'jellyfin') {
|
||||
return (
|
||||
`${baseUrl}/Items` +
|
||||
`/${imageId}` +
|
||||
`/Images/Primary` +
|
||||
'?fillHeight=200' +
|
||||
`&fillWidth=200` +
|
||||
'&quality=90'
|
||||
);
|
||||
}
|
||||
|
||||
return '';
|
||||
};
|
||||
@@ -24,11 +24,12 @@ export const getSuccessResponse = (options: {
|
||||
let pagination;
|
||||
|
||||
if (paginationItems) {
|
||||
const { startIndex, totalEntries, limit, url } = paginationItems;
|
||||
const { startIndex, totalEntries, limit, url, page } = paginationItems;
|
||||
const hasPrevPage = startIndex - limit >= 0;
|
||||
const hasNextPage = startIndex + limit <= totalEntries;
|
||||
|
||||
pagination = {
|
||||
currentPage: page,
|
||||
nextPage: hasNextPage ? getPaginationUrl(url, 'next') : null,
|
||||
prevPage: hasPrevPage ? getPaginationUrl(url, 'prev') : null,
|
||||
startIndex,
|
||||
|
||||
@@ -10,3 +10,5 @@ export * from './is-json-string';
|
||||
export * from './validate-request';
|
||||
export * from './unique-array';
|
||||
export * from './zod-validation';
|
||||
export * from './get-image-url';
|
||||
export * from './random-string';
|
||||
|
||||
10
src/server/utils/random-string.ts
Normal file
10
src/server/utils/random-string.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
export const randomString = () => {
|
||||
const charSet =
|
||||
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
||||
let string = '';
|
||||
for (let i = 0; i < 12; i += 1) {
|
||||
const randomPoz = Math.floor(Math.random() * charSet.length);
|
||||
string += charSet.substring(randomPoz, randomPoz + 1);
|
||||
}
|
||||
return string;
|
||||
};
|
||||
Reference in New Issue
Block a user