@freesewing/utils
Advanced tools
+1
-1
| { | ||
| "id": "utils", | ||
| "description": "A number of utilities, typically used by FreeSewing frontend code", | ||
| "version": "4.6.0" | ||
| "version": "4.7.0" | ||
| } |
+1
-1
| { | ||
| "name": "@freesewing/utils", | ||
| "version": "4.6.0", | ||
| "version": "4.7.0", | ||
| "description": "A number of utilities, typically used by FreeSewing frontend code", | ||
@@ -5,0 +5,0 @@ "author": "Joost De Cock <joost@joost.at> (https://codeberg.org/joostdecock)", |
+25
-35
| import tlds from 'tlds/index.json' with { type: 'json' } | ||
| import { cloudflare as cloudflareConfig } from '@freesewing/config' | ||
| import { urls } from '@freesewing/config' | ||
| import _get from 'lodash/get.js' | ||
@@ -127,45 +127,35 @@ import _set from 'lodash/set.js' | ||
| /* | ||
| * Returns the URL of a user avatar (on cloudflare) | ||
| * based on the ihash and Variant | ||
| * Returns the URL of a user avatar based on the uuid | ||
| * | ||
| * @param {string} ihash - The user's ihash | ||
| * @param {string} variant - One of the cloudflare image variants | ||
| * @param {string} uuid - The user's uuid | ||
| * @return {string} url - The image URL | ||
| */ | ||
| export function userAvatarUrl({ ihash = false, variant = 'public' }) { | ||
| /* | ||
| * If the variant is invalid, set it to the smallest thumbnail so | ||
| * people don't load enourmous images by accident | ||
| */ | ||
| if (!cloudflareConfig.variants.includes(variant)) variant = 'sq100' | ||
| /* | ||
| * Without an ihash, return something default | ||
| */ | ||
| return ihash | ||
| ? cloudflareImageUrl({ id: `uid-${ihash}`, variant }) | ||
| : cloudflareImageUrl({ id: `default-avatar`, variant }) | ||
| export function userAvatarUrl({ uuid = false }) { | ||
| // Defer to imageCdnUrl | ||
| return imageCdnUrl({ type: 'user', uuid }) | ||
| } | ||
| /* | ||
| * Returns the URL of a cloudflare image | ||
| * based on the ID and Variant | ||
| * Returns the URL of an image stored on the FreeSewing backend | ||
| * (but cached by the FreeSewing CDN) | ||
| * | ||
| * @param {string} id - The image ID | ||
| * @param {string} variant - One of the cloudflare image variants | ||
| * @return {string} url - The image URL | ||
| * @param {params} object - All params | ||
| * @param {string} params.type - The image type | ||
| * @param {string} params.id - The UUID or other id, depending on type | ||
| * @param {string} params.subId - The id for a sub-image of a post | ||
| * @param {string} params.raw - A raw path url, takes precendence | ||
| * @return {string} url - The full URL to the image on the CDN | ||
| */ | ||
| export function cloudflareImageUrl({ id = 'default-avatar', variant = 'public' }) { | ||
| /* | ||
| * Return something default so that people will actually change it | ||
| */ | ||
| if (!id || id === 'default-avatar') return cloudflareConfig.dflt | ||
| export function imageCdnUrl({ type = 'user', id = false, subId = false, raw = false }) { | ||
| if (raw && typeof raw === 'string') return `${urls.cdn}/${raw}` | ||
| let path = 'user/default-avatar' | ||
| if (typeof id === 'string') { | ||
| if (['cset', 'set', 'user', 'pattern'].includes(type)) { | ||
| path = `${type}/${id.slice(0, 1)}/${id.slice(0, 2)}/${id}.webp` | ||
| } else if (['blog', 'showcase'].includes(type)) { | ||
| path = `${type}/${id}/${subId ? subId : 'main'}.webp` | ||
| } | ||
| } | ||
| /* | ||
| * If the variant is invalid, set it to the smallest thumbnail so | ||
| * people don't load enourmous images by accident | ||
| */ | ||
| if (!cloudflareConfig.variants.includes(variant)) variant = 'sq100' | ||
| return `${cloudflareConfig.url}${id}/${variant}` | ||
| return `${urls.cdn}/${path}` | ||
| } | ||
@@ -172,0 +162,0 @@ |
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
32251
-0.63%727
-1.09%