Merge branch 'more-fixes' into shigusegubu-themes3

This commit is contained in:
Henry Jameson 2026-06-30 06:55:27 +03:00
commit ade44717e4
2 changed files with 21 additions and 15 deletions

View file

@ -71,6 +71,7 @@ export const promisedRequest = async ({
url, url,
payload, payload,
formData, formData,
cache,
credentials, credentials,
headers = {}, headers = {},
}) => { }) => {
@ -87,6 +88,10 @@ export const promisedRequest = async ({
options.headers['Content-Type'] = 'application/json' options.headers['Content-Type'] = 'application/json'
} }
if (cache) {
options.cache = cache
}
if (formData || payload) { if (formData || payload) {
options.body = formData || JSON.stringify(payload) options.body = formData || JSON.stringify(payload)
} }

View file

@ -2,6 +2,8 @@ import sum from 'hash-sum'
import localforage from 'localforage' import localforage from 'localforage'
import { chunk, throttle } from 'lodash' import { chunk, throttle } from 'lodash'
import { promisedRequest } from 'src/api/helpers.js'
import { getCssRules } from '../theme_data/css_utils.js' import { getCssRules } from '../theme_data/css_utils.js'
import { getEngineChecksum, init } from '../theme_data/theme_data_3.service.js' import { getEngineChecksum, init } from '../theme_data/theme_data_3.service.js'
@ -300,7 +302,7 @@ export const applyStyleConfig = (input) => {
adoptStyleSheets() adoptStyleSheets()
} }
export const getResourcesIndex = async (url, parser = JSON.parse) => { export const getResourcesIndex = async (url, parser = x => x) => {
const cache = 'no-store' const cache = 'no-store'
const customUrl = url.replace(/\.(\w+)$/, '.custom.$1') const customUrl = url.replace(/\.(\w+)$/, '.custom.$1')
let builtin let builtin
@ -314,14 +316,15 @@ export const getResourcesIndex = async (url, parser = JSON.parse) => {
return [ return [
k, k,
() => () =>
window promisedRequest({
.fetch(v, { cache }) url: v,
.then((data) => data.text()) cache,
.then((text) => parser(text)) })
.catch((e) => { .then(({ data: text }) => parser(text))
console.error(e) .catch((e) => {
return null console.error(e)
}), return null
}),
] ]
} else { } else {
console.error(`Unknown resource format - ${k} is a ${typeof v}`) console.error(`Unknown resource format - ${k} is a ${typeof v}`)
@ -331,18 +334,16 @@ export const getResourcesIndex = async (url, parser = JSON.parse) => {
} }
try { try {
const builtinData = await window.fetch(url, { cache }) const { data: builtinData } = await promisedRequest({ url, cache })
const builtinResources = await builtinData.json() builtin = resourceTransform(builtinData)
builtin = resourceTransform(builtinResources)
} catch { } catch {
builtin = [] builtin = []
console.warn(`Builtin resources at ${url} unavailable`) console.warn(`Builtin resources at ${url} unavailable`)
} }
try { try {
const customData = await window.fetch(customUrl, { cache }) const { data: customData } = await promisedRequest({ url: customUrl, cache })
const customResources = await customData.json() custom = resourceTransform(customData)
custom = resourceTransform(customResources)
} catch { } catch {
custom = [] custom = []
console.warn(`Custom resources at ${customUrl} unavailable`) console.warn(`Custom resources at ${customUrl} unavailable`)