mirror of
https://github.com/Kuingsmile/PicList.git
synced 2026-06-26 01:51:51 +08:00
📦 Chore(custom): update publish workflow
This commit is contained in:
@@ -99,20 +99,20 @@ function main() {
|
||||
fs.mkdirSync(outputDir, { recursive: true })
|
||||
}
|
||||
|
||||
const windowsX64Ymls = findYmlInFolder(distPath, 'windows-x64-yml', 'latest.yml')
|
||||
const windowsArm64Ymls = findYmlInFolder(distPath, 'windows-arm64-yml', 'latest.yml')
|
||||
const macX64Ymls = findYmlInFolder(distPath, 'macos-x64-yml', 'latest-mac.yml')
|
||||
const macArm64Ymls = findYmlInFolder(distPath, 'macos-arm64-yml', 'latest-mac.yml')
|
||||
const linuxX64Ymls = findYmlInFolder(distPath, 'linux-x64-yml', 'latest-linux.yml')
|
||||
const linuxArm64Ymls = findYmlInFolder(distPath, 'linux-arm64-yml', 'latest-linux-arm64.yml')
|
||||
|
||||
console.log('\nFound yml files:')
|
||||
console.log(`Windows x64: ${windowsX64Ymls.map(f => path.basename(path.dirname(f))).join(', ')}`)
|
||||
console.log(`Windows ARM64: ${windowsArm64Ymls.map(f => path.basename(path.dirname(f))).join(', ')}`)
|
||||
console.log(`macOS x64: ${macX64Ymls.map(f => path.basename(path.dirname(f))).join(', ')}`)
|
||||
console.log(`macOS ARM64: ${macArm64Ymls.map(f => path.basename(path.dirname(f))).join(', ')}`)
|
||||
console.log(`Linux x64: ${linuxX64Ymls.map(f => path.basename(path.dirname(f))).join(', ')}`)
|
||||
console.log(`Linux ARM64: ${linuxArm64Ymls.map(f => path.basename(path.dirname(f))).join(', ')}`)
|
||||
const windowsX64Ymls = findYmlInFolder(distPath, 'windows-latest-x64-nsis-yml', 'latest.yml')
|
||||
const windowsArm64Ymls = findYmlInFolder(distPath, 'windows-11-arm-arm64-nsis-yml', 'latest.yml')
|
||||
const macX64Ymls = findYmlInFolder(distPath, 'macos-15-intel-x64-dmg-yml', 'latest-mac.yml')
|
||||
const macArm64Ymls = findYmlInFolder(distPath, 'macos-latest-arm64-dmg-yml', 'latest-mac.yml')
|
||||
const linuxX64AppImageYmls = findYmlInFolder(distPath, 'ubuntu-latest-x64-AppImage-yml', 'latest-linux.yml')
|
||||
const linuxArm64AppImageYmls = findYmlInFolder(
|
||||
distPath,
|
||||
'ubuntu-24.04-arm-arm64-AppImage-yml',
|
||||
'latest-linux-arm64.yml',
|
||||
)
|
||||
const linuxX64DebYmls = findYmlInFolder(distPath, 'ubuntu-latest-x64-deb-yml', 'latest-linux.yml')
|
||||
const linuxArm64DebYmls = findYmlInFolder(distPath, 'ubuntu-24.04-arm-arm64-deb-yml', 'latest-linux-arm64.yml')
|
||||
const linuxX64RpmYmls = findYmlInFolder(distPath, 'ubuntu-latest-x64-rpm-yml', 'latest-linux.yml')
|
||||
const linuxArm64RpmYmls = findYmlInFolder(distPath, 'ubuntu-24.04-arm-arm64-rpm-yml', 'latest-linux-arm64.yml')
|
||||
|
||||
const windowsYmls = [...windowsX64Ymls, ...windowsArm64Ymls]
|
||||
if (windowsYmls.length > 0) {
|
||||
@@ -129,17 +129,20 @@ function main() {
|
||||
} else {
|
||||
console.log('\nNo macOS yml files found to combine')
|
||||
}
|
||||
const linuxX64Ymls = [...linuxX64AppImageYmls, ...linuxX64DebYmls, ...linuxX64RpmYmls]
|
||||
if (linuxX64Ymls.length > 0) {
|
||||
console.log('\nProcessing Linux x64 yml file (deduplicate only)...')
|
||||
processSingleYmlFile(linuxX64Ymls[0], path.join(outputDir, 'latest-linux.yml'))
|
||||
console.log(`\nCombining ${linuxX64Ymls.length} Linux x64 yml files...`)
|
||||
combineYmlFiles(linuxX64Ymls, path.join(outputDir, 'latest-linux.yml'))
|
||||
} else {
|
||||
console.log('\nNo Linux x64 yml files found')
|
||||
console.log('\nNo Linux x64 yml files found to combine')
|
||||
}
|
||||
|
||||
const linuxArm64Ymls = [...linuxArm64AppImageYmls, ...linuxArm64DebYmls, ...linuxArm64RpmYmls]
|
||||
if (linuxArm64Ymls.length > 0) {
|
||||
console.log('\nProcessing Linux ARM64 yml file (deduplicate only)...')
|
||||
processSingleYmlFile(linuxArm64Ymls[0], path.join(outputDir, 'latest-linux-arm64.yml'))
|
||||
console.log(`\nCombining ${linuxArm64Ymls.length} Linux arm64 yml files...`)
|
||||
combineYmlFiles(linuxArm64Ymls, path.join(outputDir, 'latest-linux-arm64.yml'))
|
||||
} else {
|
||||
console.log('\nNo Linux ARM64 yml files found')
|
||||
console.log('\nNo Linux arm64 yml files found to combine')
|
||||
}
|
||||
|
||||
console.log('\nYML combination and deduplication complete!')
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
// different platform has different format
|
||||
import pkg from '../package.json' with { type: 'json' }
|
||||
import path from 'path'
|
||||
|
||||
const version = pkg.version
|
||||
|
||||
// macos
|
||||
const darwin = [
|
||||
@@ -7,12 +11,28 @@ const darwin = [
|
||||
ext: '.dmg',
|
||||
arch: '-arm64',
|
||||
'version-file': 'latest-mac.yml',
|
||||
path: 'macos-latest-arm64-dmg-artifacts',
|
||||
},
|
||||
{
|
||||
appNameWithPrefix: 'PicList-',
|
||||
ext: '.dmg',
|
||||
arch: '-x64',
|
||||
'version-file': 'latest-mac.yml',
|
||||
path: 'macos-15-intel-x64-dmg-artifacts',
|
||||
},
|
||||
{
|
||||
appNameWithPrefix: 'PicList-',
|
||||
ext: '.zip',
|
||||
arch: '-arm64',
|
||||
'version-file': 'latest-mac.yml',
|
||||
path: 'macos-latest-arm64-dmg-artifacts',
|
||||
},
|
||||
{
|
||||
appNameWithPrefix: 'PicList-',
|
||||
ext: '.zip',
|
||||
arch: '-x64',
|
||||
'version-file': 'latest-mac.yml',
|
||||
path: 'macos-15-intel-x64-dmg-artifacts',
|
||||
},
|
||||
]
|
||||
|
||||
@@ -22,61 +42,106 @@ const linux = [
|
||||
ext: '.AppImage',
|
||||
arch: '-x86_64',
|
||||
'version-file': 'latest-linux.yml',
|
||||
path: 'ubuntu-latest-x64-AppImage-artifacts',
|
||||
},
|
||||
{
|
||||
appNameWithPrefix: 'PicList-',
|
||||
ext: '.AppImage',
|
||||
arch: '-arm64',
|
||||
'version-file': 'latest-linux.yml',
|
||||
},
|
||||
{
|
||||
appNameWithPrefix: 'PicList-',
|
||||
ext: '.snap',
|
||||
arch: '-amd64',
|
||||
'version-file': 'latest-linux.yml',
|
||||
'version-file': 'latest-linux-arm64.yml',
|
||||
path: 'ubuntu-24.04-arm-arm64-AppImage-artifacts',
|
||||
},
|
||||
{
|
||||
appNameWithPrefix: 'PicList-',
|
||||
ext: '.deb',
|
||||
arch: '-amd64',
|
||||
'version-file': 'latest-linux.yml',
|
||||
path: 'ubuntu-latest-x64-deb-artifacts',
|
||||
},
|
||||
{
|
||||
appNameWithPrefix: 'PicList-',
|
||||
ext: '.deb',
|
||||
arch: '-arm64',
|
||||
'version-file': 'latest-linux-arm64.yml',
|
||||
path: 'ubuntu-24.04-arm-arm64-deb-artifacts',
|
||||
},
|
||||
{
|
||||
appNameWithPrefix: 'PicList-',
|
||||
ext: '.rpm',
|
||||
arch: '-x86_64',
|
||||
'version-file': 'latest-linux.yml',
|
||||
path: 'ubuntu-latest-x64-rpm-artifacts',
|
||||
},
|
||||
{
|
||||
appNameWithPrefix: 'PicList-',
|
||||
ext: '.rpm',
|
||||
arch: '-aarch64',
|
||||
'version-file': 'latest-linux-arm64.yml',
|
||||
path: 'ubuntu-24.04-arm-arm64-rpm-artifacts',
|
||||
},
|
||||
{
|
||||
appNameWithPrefix: 'PicList-',
|
||||
ext: '.snap',
|
||||
arch: '-amd64',
|
||||
path: 'ubuntu-latest-x64-snap-artifacts',
|
||||
},
|
||||
]
|
||||
|
||||
// windows
|
||||
const win32 = [
|
||||
{
|
||||
appNameWithPrefix: 'PicList-Setup-',
|
||||
ext: '.exe',
|
||||
arch: '-ia32',
|
||||
'version-file': 'latest.yml',
|
||||
},
|
||||
{
|
||||
appNameWithPrefix: 'PicList-Setup-',
|
||||
ext: '.exe',
|
||||
arch: '-x64',
|
||||
'version-file': 'latest.yml',
|
||||
},
|
||||
{
|
||||
appNameWithPrefix: 'PicList-Setup-',
|
||||
ext: '.exe',
|
||||
arch: '', // 32 & 64
|
||||
'version-file': 'latest.yml',
|
||||
path: 'windows-latest-x64-nsis-artifacts',
|
||||
},
|
||||
{
|
||||
appNameWithPrefix: 'PicList-Setup-',
|
||||
ext: '.exe',
|
||||
arch: '-arm64',
|
||||
'version-file': 'latest.yml',
|
||||
path: 'windows-11-arm-arm64-nsis-artifacts',
|
||||
},
|
||||
{
|
||||
appNameWithPrefix: 'PicList-Setup-',
|
||||
ext: '.zip',
|
||||
arch: '-x64-portable',
|
||||
path: 'windows-latest-x64-zip-artifacts',
|
||||
},
|
||||
{
|
||||
appNameWithPrefix: 'PicList-Setup-',
|
||||
ext: '.zip',
|
||||
arch: '-arm64-portable',
|
||||
path: 'windows-11-arm-arm64-zip-artifacts',
|
||||
},
|
||||
{
|
||||
appNameWithPrefix: 'PicList-Setup-',
|
||||
ext: '.7z',
|
||||
arch: '-x64-portable',
|
||||
path: 'windows-latest-x64-7z-artifacts',
|
||||
},
|
||||
{
|
||||
appNameWithPrefix: 'PicList-Setup-',
|
||||
ext: '.7z',
|
||||
arch: '-arm64-portable',
|
||||
path: 'windows-11-arm-arm64-7z-artifacts',
|
||||
},
|
||||
]
|
||||
|
||||
export const generateFileName = (platformConfig, version) => {
|
||||
return `${platformConfig.appNameWithPrefix}${version}${platformConfig.arch}${platformConfig.ext}`
|
||||
}
|
||||
|
||||
export const fileList = [...darwin, ...linux, ...win32].map(platformConfig => {
|
||||
const fileName = generateFileName(platformConfig, version)
|
||||
return {
|
||||
name: fileName,
|
||||
path: path.join(platformConfig.path, fileName),
|
||||
blockMapPath: path.join(platformConfig.path, `${fileName}.blockmap`),
|
||||
}
|
||||
})
|
||||
|
||||
export default {
|
||||
darwin,
|
||||
linux,
|
||||
|
||||
@@ -1,137 +0,0 @@
|
||||
import crypto from 'node:crypto'
|
||||
import path from 'node:path'
|
||||
|
||||
import axios from 'axios'
|
||||
import fs from 'fs-extra'
|
||||
|
||||
import pkg from '../package.json' with { type: 'json' }
|
||||
const version = process.argv[2] || pkg.version
|
||||
|
||||
// Configuration
|
||||
const BASE_URL = `https://github.com/Kuingsmile/PicList/releases/download/v${version}`
|
||||
const DOWNLOAD_DIR = path.join('R:\\Downloads')
|
||||
// File information
|
||||
const files = [
|
||||
{
|
||||
name: 'PicList-x64.dmg',
|
||||
url: `${BASE_URL}/PicList-${version}-x64.dmg`,
|
||||
},
|
||||
{
|
||||
name: 'PicList-arm64.dmg',
|
||||
url: `${BASE_URL}/PicList-${version}-arm64.dmg`,
|
||||
},
|
||||
]
|
||||
|
||||
/**
|
||||
* Create progress bar string
|
||||
*/
|
||||
function getProgressBar(current, total, length = 20) {
|
||||
const progress = Math.round((current / total) * length)
|
||||
const percentage = Math.round((current / total) * 100)
|
||||
const bar = '█'.repeat(progress) + '░'.repeat(length - progress)
|
||||
return `[${bar}] ${percentage}% (${formatBytes(current)}/${formatBytes(total)})`
|
||||
}
|
||||
|
||||
/**
|
||||
* Format bytes to human-readable format
|
||||
*/
|
||||
function formatBytes(bytes, decimals = 2) {
|
||||
if (bytes === 0) return '0 Bytes'
|
||||
const k = 1024
|
||||
const sizes = ['Bytes', 'KB', 'MB', 'GB']
|
||||
const i = Math.floor(Math.log(bytes) / Math.log(k))
|
||||
return parseFloat((bytes / Math.pow(k, i)).toFixed(decimals)) + ' ' + sizes[i]
|
||||
}
|
||||
|
||||
/**
|
||||
* Download file and calculate SHA256 hash
|
||||
*/
|
||||
async function downloadAndHash(fileInfo) {
|
||||
const { url, name } = fileInfo
|
||||
const filePath = path.join(DOWNLOAD_DIR, name)
|
||||
|
||||
console.log(`\nStarting download: ${name} from ${url}`)
|
||||
|
||||
try {
|
||||
const response = await axios({
|
||||
method: 'get',
|
||||
url,
|
||||
responseType: 'stream',
|
||||
})
|
||||
|
||||
const writer = fs.createWriteStream(filePath)
|
||||
response.data.pipe(writer)
|
||||
|
||||
const hash = crypto.createHash('sha256')
|
||||
const progressTotal = parseInt(response.headers['content-length'], 10)
|
||||
let progressCurrent = 0
|
||||
|
||||
response.data.on('data', chunk => {
|
||||
hash.update(chunk)
|
||||
progressCurrent += chunk.length
|
||||
process.stdout.write(`\r${name}: ${getProgressBar(progressCurrent, progressTotal)}`)
|
||||
})
|
||||
|
||||
await new Promise((resolve, reject) => {
|
||||
writer.on('finish', resolve)
|
||||
writer.on('error', reject)
|
||||
response.data.on('error', reject)
|
||||
})
|
||||
|
||||
const hashValue = hash.digest('hex')
|
||||
console.log(`\n✅ ${name} SHA256: ${hashValue}`)
|
||||
|
||||
// Write hash to a file for reference
|
||||
await fs.writeFile(`${filePath}.sha256`, hashValue)
|
||||
console.log(`Hash saved to ${filePath}.sha256`)
|
||||
|
||||
if (process.argv.includes('--keep-files')) {
|
||||
console.log(`Keeping file: ${filePath}`)
|
||||
} else {
|
||||
await fs.remove(filePath)
|
||||
console.log(`Deleted: ${filePath}`)
|
||||
}
|
||||
|
||||
return { name, hash: hashValue }
|
||||
} catch (err) {
|
||||
console.error(`\n❌ Error processing ${name}: ${err.message}`)
|
||||
throw err
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Main function
|
||||
*/
|
||||
async function main() {
|
||||
console.log(`Generating SHA256 hashes for PicList v${version}`)
|
||||
console.log(`Download directory: ${DOWNLOAD_DIR}`)
|
||||
|
||||
try {
|
||||
// Ensure download directory exists
|
||||
await fs.ensureDir(DOWNLOAD_DIR)
|
||||
|
||||
// Start all downloads concurrently
|
||||
const results = await Promise.allSettled(files.map(downloadAndHash))
|
||||
|
||||
// Output summary
|
||||
console.log('\n===== SUMMARY =====')
|
||||
results.forEach((result, index) => {
|
||||
const fileName = files[index].name
|
||||
if (result.status === 'fulfilled') {
|
||||
console.log(`✅ ${fileName}: ${result.value.hash}`)
|
||||
} else {
|
||||
console.log(`❌ ${fileName}: Failed - ${result.reason.message}`)
|
||||
}
|
||||
})
|
||||
|
||||
// Check if all downloads were successful
|
||||
if (results.some(r => r.status === 'rejected')) {
|
||||
process.exit(1)
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(`\nCritical error: ${err.message}`)
|
||||
process.exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
main()
|
||||
@@ -36,6 +36,7 @@ cat > "$OUTPUT_FILE" << EOF
|
||||
|
||||
### macOS
|
||||
|
||||
- DMG:
|
||||
[**ARM64 (M1-M6)**](https://github.com/Kuingsmile/PicList/releases/download/v${VERSION}/PicList-${VERSION}-arm64.dmg) | [**Intel**](https://github.com/Kuingsmile/PicList/releases/download/v${VERSION}/PicList-${VERSION}-x64.dmg)
|
||||
|
||||
### Linux
|
||||
@@ -44,6 +45,8 @@ cat > "$OUTPUT_FILE" << EOF
|
||||
[**x64**](https://github.com/Kuingsmile/PicList/releases/download/v${VERSION}/PicList-${VERSION}-x86_64.AppImage) | [**ARM64**](https://github.com/Kuingsmile/PicList/releases/download/v${VERSION}/PicList-${VERSION}-arm64.AppImage)
|
||||
- deb:
|
||||
[**x64**](https://github.com/Kuingsmile/PicList/releases/download/v${VERSION}/Piclist-${VERSION}-amd64.deb) | [**ARM64**](https://github.com/Kuingsmile/PicList/releases/download/v${VERSION}/Piclist-${VERSION}-arm64.deb)
|
||||
- rpm:
|
||||
[**x64**](https://github.com/Kuingsmile/PicList/releases/download/v${VERSION}/Piclist-${VERSION}-x86_64.rpm) | [**ARM64**](https://github.com/Kuingsmile/PicList/releases/download/v${VERSION}/Piclist-${VERSION}-aarch64.rpm)
|
||||
- snap:
|
||||
[**x64**](https://github.com/Kuingsmile/PicList/releases/download/v${VERSION}/Piclist-${VERSION}-amd64.snap)
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import pkg from '../package.json' with { type: 'json' }
|
||||
|
||||
const version = pkg.version
|
||||
// TODO: use the same name format
|
||||
|
||||
const generateURL = (platform, ext, prefix = 'PicList-') => {
|
||||
return `https://release.piclist.cn/latest/${prefix}${version}${platform}${ext}`
|
||||
}
|
||||
@@ -9,18 +10,37 @@ const template = `
|
||||
### 加速下载地址
|
||||
|
||||
#### MacOS
|
||||
[PicList-${version}-arm64.dmg](${generateURL('-arm64', '.dmg', 'PicList-')})
|
||||
[PicList-${version}-x64.dmg](${generateURL('-x64', '.dmg', 'PicList-')})
|
||||
[PicList-${version}-universal.dmg](${generateURL('-universal', '.dmg', 'PicList-')})
|
||||
|
||||
- DMG:
|
||||
|
||||
[PicList-${version}-x64.dmg](${generateURL('-x64', '.dmg', 'PicList-')}) | [PicList-${version}-arm64.dmg](${generateURL('-arm64', '.dmg', 'PicList-')})
|
||||
|
||||
#### Windows
|
||||
[PicList-Setup-${version}-ia32.exe](${generateURL('-ia32', '.exe', 'PicList-Setup-')})
|
||||
[PicList-Setup-${version}-x64.exe](${generateURL('-x64', '.exe', 'PicList-Setup-')})
|
||||
[PicList-Setup-${version}-arm64.exe](${generateURL('-arm64', '.exe', 'PicList-Setup-')})
|
||||
[PicList-Setup-${version}.exe](${generateURL('', '.exe', 'PicList-Setup-')})
|
||||
|
||||
- Installer:
|
||||
[PicList-Setup-${version}-x64.exe](${generateURL('-x64', '.exe', 'PicList-Setup-')}) | [PicList-Setup-${version}-arm64.exe](${generateURL('-arm64', '.exe', 'PicList-Setup-')})
|
||||
|
||||
- Portable:
|
||||
|
||||
[PicList-Setup-${version}-x64-portable.zip](${generateURL('-x64-portable', '.zip', 'PicList-Setup-')}) | [PicList-Setup-${version}-arm64-portable.zip](${generateURL('-arm64-portable', '.zip', 'PicList-Setup-')}) | [PicList-Setup-${version}-x64-portable.7z](${generateURL('-x64-portable', '.7z', 'PicList-Setup-')}) | [PicList-Setup-${version}-arm64-portable.7z](${generateURL('-arm64-portable', '.7z', 'PicList-Setup-')})
|
||||
|
||||
#### Linux
|
||||
[PicList-${version}.AppImage](${generateURL('', '.AppImage', 'PicList-')})
|
||||
[piclist_${version}_amd64.snap](${generateURL('_amd64', '.snap', 'piclist_')})`
|
||||
|
||||
- AppImage:
|
||||
|
||||
[PicList-${version}-x86_64.AppImage](${generateURL('-x86_64', '.AppImage', 'PicList-')}) | [PicList-${version}-arm64.AppImage](${generateURL('-arm64', '.AppImage', 'PicList-')})
|
||||
|
||||
- Deb:
|
||||
|
||||
[PicList-${version}-amd64.deb](${generateURL('-amd64', '.deb', 'PicList-')}) | [PicList-${version}-arm64.deb](${generateURL('-arm64', '.deb', 'PicList-')})
|
||||
|
||||
- Rpm:
|
||||
|
||||
[PicList-${version}-x86_64.rpm](${generateURL('-x86_64', '.rpm', 'PicList-')}) | [PicList-${version}-aarch64.rpm](${generateURL('-aarch64', '.rpm', 'PicList-')})
|
||||
|
||||
- Snap:
|
||||
|
||||
[PicList-${version}-amd64.snap](${generateURL('-amd64', '.snap', 'PicList-')})
|
||||
`
|
||||
|
||||
console.log(template)
|
||||
|
||||
99
scripts/upload-to-s3.js
Normal file
99
scripts/upload-to-s3.js
Normal file
@@ -0,0 +1,99 @@
|
||||
import dotenv from 'dotenv'
|
||||
import { fileList } from './config.js'
|
||||
import fs from 'fs-extra'
|
||||
import mime from 'mime'
|
||||
import path from 'node:path'
|
||||
import { S3Client } from '@aws-sdk/client-s3'
|
||||
import { Upload } from '@aws-sdk/lib-storage'
|
||||
|
||||
dotenv.config()
|
||||
|
||||
const bucket = 'piclist-dl'
|
||||
const folder = `latest/`
|
||||
const R2_SECRET_ID = process.env.R2_SECRET_ID
|
||||
const R2_SECRET_KEY = process.env.R2_SECRET_KEY
|
||||
const R2_ACCOUNT_ID = process.env.R2_ACCOUNT_ID
|
||||
|
||||
console.log('fileList to upload:', JSON.stringify(fileList, null, 2))
|
||||
|
||||
const ymlFileList = ['latest-mac.yml', 'latest.yml', 'latest-linux.yml', 'latest-linux-arm64.yml']
|
||||
|
||||
const args = process.argv.slice(2)
|
||||
const exePath = args[0] || './artifacts'
|
||||
const ymlPath = args[1] || './dist_electron/combined'
|
||||
const idDev = args[2] || true
|
||||
|
||||
const S3Options = {
|
||||
credentials: {
|
||||
accessKeyId: R2_SECRET_ID,
|
||||
secretAccessKey: R2_SECRET_KEY,
|
||||
},
|
||||
endpoint: `https://${R2_ACCOUNT_ID}.r2.cloudflarestorage.com`,
|
||||
sslEnabled: true,
|
||||
region: 'auto',
|
||||
}
|
||||
|
||||
const uploadFile = async filePath => {
|
||||
try {
|
||||
console.log('[INFO]: uploading file:', filePath)
|
||||
const client = new S3Client(S3Options)
|
||||
if (fs.existsSync(filePath)) {
|
||||
const uploadDistToS3 = new Upload({
|
||||
client,
|
||||
params: {
|
||||
Bucket: bucket,
|
||||
Key: `${folder}${path.basename(filePath)}`,
|
||||
Body: fs.createReadStream(filePath),
|
||||
ContentType: path.basename(filePath).endsWith('.yml')
|
||||
? mime.getType(path.basename(filePath))
|
||||
: 'application/octet-stream',
|
||||
},
|
||||
})
|
||||
uploadDistToS3.on('httpUploadProgress', progress => {
|
||||
console.log(`[INFO]: ${path.basename(filePath)} - ${progress.loaded}/${progress.total}`)
|
||||
})
|
||||
if (idDev) {
|
||||
console.log('[DEV]: upload params:', {
|
||||
Bucket: bucket,
|
||||
Key: `${folder}${path.basename(filePath)}`,
|
||||
Body: '<<stream>>',
|
||||
ContentType: path.basename(filePath).endsWith('.yml')
|
||||
? mime.getType(path.basename(filePath))
|
||||
: 'application/octet-stream',
|
||||
})
|
||||
} else {
|
||||
await uploadDistToS3.done()
|
||||
}
|
||||
} else {
|
||||
console.warn('[Warn] File not found:', filePath)
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('[ERROR]: upload failed:', e)
|
||||
}
|
||||
}
|
||||
|
||||
const upload = async () => {
|
||||
console.log('[INFO]: Starting upload to S3...')
|
||||
console.log('[INFO]: upload exePath:', exePath)
|
||||
for (const file of fileList) {
|
||||
const installerPath = path.join(exePath, file.path)
|
||||
await uploadFile(installerPath)
|
||||
}
|
||||
|
||||
console.log('[INFO]: upload blockmap files...')
|
||||
for (const file of fileList) {
|
||||
const installerPath = path.join(exePath, file.blockMapPath)
|
||||
await uploadFile(installerPath)
|
||||
}
|
||||
|
||||
for (const ymlFile of ymlFileList) {
|
||||
const ymlFilePath = path.join(ymlPath, ymlFile)
|
||||
await uploadFile(ymlFilePath)
|
||||
}
|
||||
}
|
||||
|
||||
const main = async () => {
|
||||
await upload()
|
||||
}
|
||||
|
||||
main()
|
||||
Reference in New Issue
Block a user