1
0
mirror of https://gitcode.com/github-mirrors/react-native-update-cli.git synced 2025-12-17 10:52:34 +08:00
Code Issues Packages Projects Releases Wiki Activity GitHub Gitee

more cresc config

This commit is contained in:
sunnylqm
2025-02-18 22:37:09 +08:00
parent e713f4bbd1
commit 546faef83f
3 changed files with 29 additions and 17 deletions

View File

@@ -6,16 +6,19 @@ import ProgressBar from 'progress';
import packageJson from '../package.json';
import tcpp from 'tcp-ping';
import filesizeParser from 'filesize-parser';
import { pricingPageUrl } from './utils';
import { pricingPageUrl } from './utils/constants';
import type { Session } from 'types';
import FormData from 'form-data';
import { credentialFile } from 'utils/constants';
const tcpPing = util.promisify(tcpp.ping);
let session: Session | undefined;
let savedSession: Session | undefined;
const defaultEndpoint = 'https://update.reactnative.cn/api';
const defaultEndpoint = global.IS_CRESC
? 'https://api.cresc.dev'
: 'https://update.reactnative.cn/api';
let host = process.env.PUSHY_REGISTRY || defaultEndpoint;
const userAgent = `react-native-update-cli/${packageJson.version}`;
@@ -26,14 +29,16 @@ export const replaceSession = (newSession: { token: string }) => {
session = newSession;
};
export const loadSession = async () => {
if (fs.existsSync('.update')) {
if (fs.existsSync(credentialFile)) {
try {
replaceSession(JSON.parse(fs.readFileSync('.update', 'utf8')));
replaceSession(JSON.parse(fs.readFileSync(credentialFile, 'utf8')));
savedSession = session;
} catch (e) {
console.error(
'Failed to parse file `.update`. Try to remove it manually.',
`Failed to parse file ${credentialFile}. Try to remove it manually.`,
);
throw e;
}
@@ -45,14 +50,14 @@ export const saveSession = () => {
if (session !== savedSession) {
const current = session;
const data = JSON.stringify(current, null, 4);
fs.writeFileSync('.update', data, 'utf8');
fs.writeFileSync(credentialFile, data, 'utf8');
savedSession = current;
}
};
export const closeSession = () => {
if (fs.existsSync('.update')) {
fs.unlinkSync('.update');
if (fs.existsSync(credentialFile)) {
fs.unlinkSync(credentialFile);
savedSession = undefined;
}
session = undefined;
@@ -137,7 +142,7 @@ export async function uploadFile(fn: string, key?: string) {
);
}
const bar = new ProgressBar(' 上传中 [:bar] :percent :etas', {
const bar = new ProgressBar(' Uploading [:bar] :percent :etas', {
complete: '=',
incomplete: ' ',
total: fileSize,
@@ -145,9 +150,9 @@ export async function uploadFile(fn: string, key?: string) {
const form = new FormData();
Object.entries(formData).forEach(([k, v]) => {
for (const [k, v] of Object.entries(formData)) {
form.append(k, v);
});
}
const fileStream = fs.createReadStream(fn);
fileStream.on('data', (data) => {
bar.tick(data.length);