@@ -35,7 +35,7 @@ export async function downloadUrl(dispatch: TaskEventDispatcher, url: string, ta
35
35
secureProtocol : 'TLSv1_2_method' ,
36
36
} ;
37
37
const response : Response = await fetch (
38
- url , {
38
+ url , {
39
39
headers,
40
40
agent : systemProxy . http_proxy ? new HttpsProxyAgent ( systemProxy . http_proxy as string , agentOptions ) : undefined ,
41
41
} ) ;
@@ -52,7 +52,7 @@ export async function downloadUrl(dispatch: TaskEventDispatcher, url: string, ta
52
52
} ) ;
53
53
54
54
const finished = util . promisify ( stream . finished ) ;
55
-
55
+
56
56
const bufferStream = new stream . PassThrough ( ) ;
57
57
const writeStream = fs . createWriteStream ( targetPath ) ;
58
58
@@ -111,6 +111,7 @@ export async function downloadUrlPro(dispatch: TaskEventDispatcher, url: string,
111
111
const { systemProxy } = await getSystemProxy ( ) ;
112
112
const filename : string = path . basename ( url ) ;
113
113
const tmpFilePath : string = targetPath + ".tmp" ;
114
+ const isCivitai = url . includes ( "civitai" ) ;
114
115
115
116
try {
116
117
@@ -130,7 +131,7 @@ export async function downloadUrlPro(dispatch: TaskEventDispatcher, url: string,
130
131
const fileSize : number = fs . existsSync ( tmpFilePath ) ? fs . statSync ( tmpFilePath ) . size : 0 ;
131
132
let headers : Record < string , string > = fileSize > 0 ? { Range : `bytes=${ fileSize } -` } : { } ;
132
133
133
- if ( url . indexOf ( "civitai" ) > - 1 ) {
134
+ if ( isCivitai ) {
134
135
const token = getCivitAIToken ( false ) ;
135
136
if ( token ) {
136
137
headers [ "Authorization" ] = token
@@ -147,10 +148,15 @@ export async function downloadUrlPro(dispatch: TaskEventDispatcher, url: string,
147
148
148
149
if ( ! response . ok ) {
149
150
throw new Error ( `Failed to download from ${ url } . Status: ${ response . status } ${ response . statusText } ` ) ;
150
- } else {
151
- console . log ( "Download Reponse from " + url ) ;
152
151
}
153
152
153
+ if ( isCivitai && response . redirected && response . url . startsWith ( 'https://civitai.com/login' ) ) {
154
+ // is download from civitai but this model need login to download
155
+ throw new Error ( `Failed to download this model without config civitai token. You can config your token in settings before continue` ) ;
156
+ }
157
+
158
+ console . log ( "Download Reponse from " + url ) ;
159
+
154
160
const totalSize = Number ( response . headers . get ( 'content-length' ) ) + fileSize ;
155
161
let downloadedSize = fileSize ;
156
162
@@ -234,4 +240,4 @@ export async function downloadUrlPro(dispatch: TaskEventDispatcher, url: string,
234
240
} catch ( error ) {
235
241
throw new Error ( `Error downloading from ${ url } : ${ error } ` ) ;
236
242
}
237
- }
243
+ }
0 commit comments