🐛 Fix(custom): fix the double v in version page

This commit is contained in:
Kuingsmile
2026-01-05 13:36:18 +08:00
parent 4d074e8ed2
commit 5460bd785a
16 changed files with 118 additions and 511 deletions

86
scripts/auto-winget.js Normal file
View File

@@ -0,0 +1,86 @@
import dotenv from 'dotenv'
import packagej from '../package.json' with { type: 'json' }
import * as fsWalk from '@nodelib/fs.walk'
import fs from 'fs-extra'
import path from 'node:path'
import yaml from 'yaml'
import axios from 'axios'
import { exec } from 'node:child_process'
dotenv.config()
const version = packagej.version
const walkPath = fsWalk.walkSync('.winget').slice(-1)[0]?.dirent.parentPath
const oldVersion = path.basename(walkPath)
const targetPath = path.resolve(`${path.dirname(walkPath)}/${version}`)
fs.renameSync(walkPath, targetPath)
const fileList = [
path.join(targetPath, 'Kuingsmile.PicList.installer.yaml'),
path.join(targetPath, 'Kuingsmile.PicList.locale.en-US.yaml'),
path.join(targetPath, 'Kuingsmile.PicList.yaml'),
]
function relaceVersion(filePath) {
let content = fs.readFileSync(filePath, 'utf-8')
content = content.replaceAll(oldVersion, version)
fs.writeFileSync(filePath, content, 'utf-8')
}
fileList.forEach(filePath => {
relaceVersion(filePath)
})
const releaseAPI = 'https://api.github.com/repos/Kuingsmile/piclist/releases/latest'
const response = await axios.get(releaseAPI, {
headers: {
Accept: 'application/vnd.github+json',
},
})
const releaseData = response.data
const fileNameList = [`PicList-Setup-${version}-arm64.exe`, `PicList-Setup-${version}.exe`]
const sha256List = []
fileNameList.forEach(fileName => {
const asset = releaseData.assets.find(a => a.name === fileName)
if (asset) {
sha256List.push({
fileName,
sha256: asset.digest.replace('sha256:', '').toUpperCase(),
})
}
})
const insatllerContent = yaml.parseDocument(fs.readFileSync(fileList[0], 'utf-8'))
const installers = insatllerContent.get('Installers')
const updatedInstallers = installers.toJSON().map(installer => {
const matched = sha256List.find(
item => installer.Architecture === (item.fileName.includes('arm64') ? 'arm64' : 'x64'),
)
if (matched) {
return {
...installer,
InstallerSha256: matched.sha256,
}
}
return installer
})
insatllerContent.set('Installers', updatedInstallers)
fs.writeFileSync(fileList[0], insatllerContent.toString(), 'utf-8')
const cmd = `wingetcreate.exe submit -p "PicList v${version}" -t "${process.env.GH_TOKEN}" .\\.winget\\manifests\\k\\Kuingsmile\\PicList\\${version}\\`
exec(cmd, (error, stdout, stderr) => {
if (error) {
console.error(`Error executing command: ${error.message}`)
return
}
if (stderr) {
console.error(`Command stderr: ${stderr}`)
return
}
console.log(`Command stdout: ${stdout}`)
})

View File

@@ -2,7 +2,7 @@ import { readFileSync, writeFileSync } from 'node:fs'
import { dirname, join } from 'node:path'
import { fileURLToPath } from 'node:url'
import { load } from 'js-yaml'
import yaml from 'yaml'
const languageFileName = 'zh-CN.yml'
const __filename = fileURLToPath(import.meta.url)
@@ -14,7 +14,7 @@ const languageFile = join(i18nFolder, languageFileName)
const langFile = readFileSync(languageFile, 'utf8')
const obj = load(langFile)
const obj = yaml.parseDocument(langFile).toJSON()
const keys = Object.keys(obj)

View File

@@ -1,63 +0,0 @@
// upload dist bundled-app to r2
require('dotenv').config()
const S3Client = require('@aws-sdk/client-s3')
const Upload = require('@aws-sdk/lib-storage')
const pkg = require('../package.json')
const configList = require('./config')
const fs = require('node:fs')
const path = require('node:path')
const BUCKET = 'piclist-dl'
const VERSION = pkg.version
const FILE_PATH = 'beta/'
const ACCOUNT_ID = process.env.R2_ACCOUNT_ID
const SECRET_ID = process.env.R2_SECRET_ID
const SECRET_KEY = process.env.R2_SECRET_KEY
const uploadFile = async () => {
try {
const platform = process.platform
if (configList[platform]) {
for (const [index, config] of configList[platform].entries()) {
const fileName = `${config.appNameWithPrefix}${VERSION}${config.arch}${config.ext}`
const distPath = path.join(__dirname, '../dist_electron')
console.log('[PicList Dist] Uploading...', fileName, `${index + 1}/${configList[platform].length}`)
const fileStream = fs.createReadStream(path.join(distPath, fileName))
const options = {
credentials: {
accessKeyId: SECRET_ID,
secretAccessKey: SECRET_KEY,
},
endpoint: `https://${ACCOUNT_ID}.r2.cloudflarestorage.com`,
tls: true,
region: 'auto',
}
const client = new S3Client.S3Client(options)
const parallelUploads3 = new Upload.Upload({
client,
params: {
Bucket: BUCKET,
Key: `${FILE_PATH}${fileName}`,
Body: fileStream,
ContentType: 'application/octet-stream',
Metadata: {
description: 'uploaded by PicList',
},
},
})
parallelUploads3.on('httpUploadProgress', progress => {
const progressBar = Math.round((progress.loaded / progress.total) * 100)
process.stdout.write(`\r${progressBar}% ${fileName}`)
})
console.log('\n')
await parallelUploads3.done()
console.log(`${fileName} uploaded!`)
}
} else {
console.warn('platform not supported!', platform)
}
} catch (err) {
console.error(err)
}
}
uploadFile()

View File

@@ -1,132 +0,0 @@
// upload dist bundled-app to r2
require('dotenv').config()
const S3Client = require('@aws-sdk/client-s3')
const Upload = require('@aws-sdk/lib-storage')
const pkg = require('../package.json')
const configList = require('./config')
const fs = require('node:fs')
const path = require('node:path')
const yaml = require('js-yaml')
const mime = require('mime')
const BUCKET = 'piclist-dl'
const VERSION = pkg.version
const FILE_PATH = 'latest/'
const ACCOUNT_ID = process.env.R2_ACCOUNT_ID
const SECRET_ID = process.env.R2_SECRET_ID
const SECRET_KEY = process.env.R2_SECRET_KEY
const options = {
credentials: {
accessKeyId: SECRET_ID,
secretAccessKey: SECRET_KEY,
},
endpoint: `https://${ACCOUNT_ID}.r2.cloudflarestorage.com`,
tls: true,
region: 'auto',
}
const removeDupField = path => {
const file = fs.readFileSync(path, 'utf8')
const data = yaml.load(file)
const filesMap = {}
data.files.forEach(file => {
const key = file.url + file.sha512 + file.size
filesMap[key] = file
})
data.files = Object.values(filesMap)
const newYml = yaml.dump(data, { lineWidth: -1 })
fs.writeFileSync(path, newYml, 'utf8')
}
const uploadFile = async () => {
try {
const platform = process.platform
if (!configList[platform]) {
console.warn('platform not supported!', platform)
return
}
let versionFileHasUploaded = true
for (const [index, config] of configList[platform].entries()) {
const fileName = `${config.appNameWithPrefix}${VERSION}${config.arch}${config.ext}`
const distPath = path.join(__dirname, '../dist_electron')
const versionFileName = config['version-file']
console.log('[PicList Dist] Uploading...', fileName, `${index + 1}/${configList[platform].length}`)
const fileStream = fs.createReadStream(path.join(distPath, fileName))
const client = new S3Client.S3Client(options)
const parallelUploads3 = new Upload.Upload({
client,
params: {
Bucket: BUCKET,
Key: `${FILE_PATH}${fileName}`,
Body: fileStream,
ContentType: 'application/octet-stream',
Metadata: {
description: 'uploaded by PicList',
},
},
})
parallelUploads3.on('httpUploadProgress', progress => {
const progressBar = Math.round((progress.loaded / progress.total) * 100)
process.stdout.write(`\r${progressBar}% ${fileName}`)
})
console.log('\n')
await parallelUploads3.done()
console.log(`${fileName} uploaded!`)
if (!versionFileHasUploaded) {
console.log('[PicList Version File] Uploading...', versionFileName)
let versionFilePath
if (platform === 'win32') {
versionFilePath = path.join(distPath, 'latest.yml')
} else if (platform === 'darwin') {
versionFilePath = path.join(distPath, 'latest-mac.yml')
} else {
versionFilePath = path.join(distPath, 'latest-linux.yml')
}
removeDupField(versionFilePath)
const versionFileStream = fs.createReadStream(versionFilePath)
const uploadVersionFileToRoot = new Upload.Upload({
client,
params: {
Bucket: BUCKET,
Key: `${versionFileName}`,
Body: versionFileStream,
ContentType: mime.getType(versionFileName),
Metadata: {
description: 'uploaded by PicList',
},
},
})
console.log('\nUploading version file to root...')
await uploadVersionFileToRoot.done()
console.log(`${versionFileName} uploaded!`)
versionFileStream.close()
const versionFileStream2 = fs.createReadStream(versionFilePath)
const uploadVersionFileToLatest = new Upload.Upload({
client,
params: {
Bucket: BUCKET,
Key: `${FILE_PATH}${versionFileName}`,
Body: versionFileStream2,
ContentType: mime.getType(versionFileName),
Metadata: {
description: 'uploaded by PicList',
},
},
})
console.log('\nUploading version file to latest...')
await uploadVersionFileToLatest.done()
console.log(`${versionFileName} uploaded!`)
versionFileStream2.close()
versionFileHasUploaded = true
}
}
} catch (err) {
console.error(err)
}
}
uploadFile()