- Updated ModelSource type to include 'huggingface'. - Enhanced MODEL_SOURCE_LABELS for better clarity. - Introduced defaultModelSource function to determine default source based on service route. - Modified AppSettings to include language and serviceRoute. - Created end-to-end tests for language and service route settings. - Added unit tests for application language and service preferences. - Updated free models test to reflect new catalog naming conventions. - Enhanced official API tests to ensure correct handling of service regions. - Adjusted release artifact tests to accommodate internationalization. - Updated SQLite migration and storage tests to include new preferences.
41 lines
1.4 KiB
JavaScript
41 lines
1.4 KiB
JavaScript
import { createHash } from 'node:crypto'
|
|
import { readFileSync, readdirSync } from 'node:fs'
|
|
import path from 'node:path'
|
|
|
|
export const DISTRIBUTIONS = ['domestic', 'international']
|
|
export const distributionName = (distribution) =>
|
|
distribution === 'international' ? 'NCurator' : '馆长'
|
|
export const distributionStorage = (distribution) =>
|
|
distribution === 'international' ? 'r2' : 'cos'
|
|
export const assertDistribution = (value) => {
|
|
if (!DISTRIBUTIONS.includes(value)) throw new Error(`invalid release distribution: ${value}`)
|
|
return value
|
|
}
|
|
export const hashSharedEntries = (entries) => {
|
|
const hash = createHash('sha256')
|
|
for (const [name, content] of [...entries].sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))) {
|
|
hash
|
|
.update(name)
|
|
.update('\0')
|
|
.update(createHash('sha256').update(content).digest('hex'))
|
|
.update('\n')
|
|
}
|
|
return hash.digest('hex')
|
|
}
|
|
export const hashSharedApp = (appDirectory) => {
|
|
const entries = []
|
|
const walk = (directory) => {
|
|
for (const entry of readdirSync(directory, { withFileTypes: true })) {
|
|
const file = path.join(directory, entry.name)
|
|
if (entry.isDirectory()) walk(file)
|
|
else if (entry.isFile())
|
|
entries.push([
|
|
path.relative(appDirectory, file).replaceAll(path.sep, '/'),
|
|
readFileSync(file)
|
|
])
|
|
}
|
|
}
|
|
walk(path.join(appDirectory, 'out'))
|
|
return hashSharedEntries(entries)
|
|
}
|