@@ -6,16 +6,19 @@ import ProgressBar from 'progress';
66import packageJson from '../package.json' ;
77import tcpp from 'tcp-ping' ;
88import filesizeParser from 'filesize-parser' ;
9- import { pricingPageUrl } from './utils' ;
9+ import { pricingPageUrl } from './utils/constants ' ;
1010import type { Session } from 'types' ;
1111import FormData from 'form-data' ;
12+ import { credentialFile } from 'utils/constants' ;
1213
1314const tcpPing = util . promisify ( tcpp . ping ) ;
1415
1516let session : Session | undefined ;
1617let savedSession : Session | undefined ;
1718
18- const defaultEndpoint = 'https://update.reactnative.cn/api' ;
19+ const defaultEndpoint = global . IS_CRESC
20+ ? 'https://api.cresc.dev'
21+ : 'https://update.reactnative.cn/api' ;
1922let host = process . env . PUSHY_REGISTRY || defaultEndpoint ;
2023
2124const userAgent = `react-native-update-cli/${ packageJson . version } ` ;
@@ -26,14 +29,16 @@ export const replaceSession = (newSession: { token: string }) => {
2629 session = newSession ;
2730} ;
2831
32+
33+
2934export const loadSession = async ( ) => {
30- if ( fs . existsSync ( '.update' ) ) {
35+ if ( fs . existsSync ( credentialFile ) ) {
3136 try {
32- replaceSession ( JSON . parse ( fs . readFileSync ( '.update' , 'utf8' ) ) ) ;
37+ replaceSession ( JSON . parse ( fs . readFileSync ( credentialFile , 'utf8' ) ) ) ;
3338 savedSession = session ;
3439 } catch ( e ) {
3540 console . error (
36- ' Failed to parse file `.update`. Try to remove it manually.' ,
41+ ` Failed to parse file ${ credentialFile } . Try to remove it manually.` ,
3742 ) ;
3843 throw e ;
3944 }
@@ -45,14 +50,14 @@ export const saveSession = () => {
4550 if ( session !== savedSession ) {
4651 const current = session ;
4752 const data = JSON . stringify ( current , null , 4 ) ;
48- fs . writeFileSync ( '.update' , data , 'utf8' ) ;
53+ fs . writeFileSync ( credentialFile , data , 'utf8' ) ;
4954 savedSession = current ;
5055 }
5156} ;
5257
5358export const closeSession = ( ) => {
54- if ( fs . existsSync ( '.update' ) ) {
55- fs . unlinkSync ( '.update' ) ;
59+ if ( fs . existsSync ( credentialFile ) ) {
60+ fs . unlinkSync ( credentialFile ) ;
5661 savedSession = undefined ;
5762 }
5863 session = undefined ;
@@ -137,17 +142,17 @@ export async function uploadFile(fn: string, key?: string) {
137142 ) ;
138143 }
139144
140- const bar = new ProgressBar ( ' 上传中 [:bar] :percent :etas' , {
145+ const bar = new ProgressBar ( ' Uploading [:bar] :percent :etas' , {
141146 complete : '=' ,
142147 incomplete : ' ' ,
143148 total : fileSize ,
144149 } ) ;
145150
146151 const form = new FormData ( ) ;
147152
148- Object . entries ( formData ) . forEach ( ( [ k , v ] ) => {
153+ for ( const [ k , v ] of Object . entries ( formData ) ) {
149154 form . append ( k , v ) ;
150- } ) ;
155+ }
151156 const fileStream = fs . createReadStream ( fn ) ;
152157 fileStream . on ( 'data' , ( data ) => {
153158 bar . tick ( data . length ) ;
0 commit comments