give up on downloader idea. Use file from assets.
This commit is contained in:
@ -138,7 +138,7 @@ export class WhisperFile {
|
||||
return Paths.join(WHISPER_MODEL_PATH, this.targetFileName as string);
|
||||
}
|
||||
|
||||
get targetPartPath () {
|
||||
get targetPartPath() {
|
||||
return this.targetPath + ".part";
|
||||
}
|
||||
|
||||
@ -146,6 +146,10 @@ export class WhisperFile {
|
||||
return new File(this.targetPath);
|
||||
}
|
||||
|
||||
get targetPartFile() {
|
||||
return new File(this.targetPartPath);
|
||||
}
|
||||
|
||||
async getTargetInfo() {
|
||||
return await FileSystem.getInfoAsync(this.targetPath);
|
||||
}
|
||||
@ -156,7 +160,9 @@ export class WhisperFile {
|
||||
|
||||
async updateTargetExistence() {
|
||||
this.does_target_exist = (await this.getTargetInfo()).exists;
|
||||
console.log("Determining if %s exists: %s", this.targetPath, this.does_target_exist)
|
||||
this.does_part_target_exist = (await this.getTargetPartInfo()).exists;
|
||||
console.log("Determining if %s exists: %s", this.targetPartPath, this.does_part_target_exist)
|
||||
}
|
||||
|
||||
public async getTargetSha() {
|
||||
@ -171,7 +177,6 @@ export class WhisperFile {
|
||||
});
|
||||
const data = strToArrBuf(strData);
|
||||
|
||||
|
||||
const digest = await Crypto.digest(
|
||||
Crypto.CryptoDigestAlgorithm.SHA256,
|
||||
data
|
||||
@ -192,14 +197,15 @@ export class WhisperFile {
|
||||
|
||||
delete(ignoreErrors = true) {
|
||||
try {
|
||||
this.targetFile.delete();
|
||||
this.does_target_exist && this.targetFile.delete();
|
||||
this.does_part_target_exist && this.targetPartFile.delete();
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
if (!ignoreErrors) {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
console.debug("Created %s", WHISPER_MODEL_DIR);
|
||||
console.debug("Successfully deleted %s and %s", this.targetPartPath, this.targetPath);
|
||||
}
|
||||
|
||||
get modelUrl() {
|
||||
@ -260,9 +266,9 @@ export class WhisperFile {
|
||||
onData?: DownloadCallback | undefined;
|
||||
onComplete?: CompletionCallback | undefined;
|
||||
} = {
|
||||
onData: undefined,
|
||||
onComplete: undefined,
|
||||
}
|
||||
onData: undefined,
|
||||
onComplete: undefined,
|
||||
}
|
||||
) {
|
||||
await this.syncHfMetadata();
|
||||
|
||||
@ -277,23 +283,26 @@ export class WhisperFile {
|
||||
// If it exists, load the existing data.
|
||||
await this.updateTargetExistence();
|
||||
|
||||
if (this.does_part_target_exist) {
|
||||
options.onComplete && options.onComplete(this)
|
||||
}
|
||||
|
||||
try {
|
||||
const existingData = this.does_target_exist
|
||||
? await FileSystem.readAsStringAsync(this.targetPath, {
|
||||
encoding: FileSystem.EncodingType.Base64,
|
||||
})
|
||||
: undefined;
|
||||
// const existingData = this.does_target_exist
|
||||
// ? await FileSystem.readAsStringAsync(this.targetPath, {
|
||||
// encoding: FileSystem.EncodingType.Base64,
|
||||
// })
|
||||
// : undefined;
|
||||
|
||||
// Create the resumable.
|
||||
return FileSystem.createDownloadResumable(
|
||||
this.modelUrl,
|
||||
this.targetPath,
|
||||
this.targetPartPath,
|
||||
{},
|
||||
async (data: FileSystem.DownloadProgressData) => {
|
||||
console.log(
|
||||
"Downloading %s: %d of %d",
|
||||
this.targetPartPath,
|
||||
data.totalBytesExpectedToWrite,
|
||||
data.totalBytesWritten
|
||||
);
|
||||
|
||||
// console.debug("yes, I'm still downloading");
|
||||
try {
|
||||
this.download_data = data;
|
||||
@ -304,7 +313,7 @@ export class WhisperFile {
|
||||
try {
|
||||
await this.syncHfMetadata();
|
||||
} catch (err) {
|
||||
console.error("Failed to update HuggingFace metadata: %s", err)
|
||||
console.error("Failed to update HuggingFace metadata: %s", err);
|
||||
}
|
||||
|
||||
// try {
|
||||
@ -316,13 +325,17 @@ export class WhisperFile {
|
||||
try {
|
||||
await this.updateTargetExistence();
|
||||
} catch (err) {
|
||||
console.error("Failed to update target existence: %s", err)
|
||||
console.error("Failed to update target existence: %s", err);
|
||||
}
|
||||
if (options.onData) await options.onData(this);
|
||||
|
||||
if (data.totalBytesExpectedToWrite === 0) {
|
||||
console.debug("Finalizing; copying from %s -> %s", this.targetPartPath, this.targetPath);
|
||||
await FileSystem.copyAsync({
|
||||
if (data.totalBytesExpectedToWrite === data.totalBytesWritten) {
|
||||
console.debug(
|
||||
"Finalizing; copying from %s -> %s",
|
||||
this.targetPartPath,
|
||||
this.targetPath
|
||||
);
|
||||
await FileSystem.moveAsync({
|
||||
from: this.targetPartPath,
|
||||
to: this.targetPath,
|
||||
});
|
||||
@ -330,7 +343,7 @@ export class WhisperFile {
|
||||
options.onComplete && options.onComplete(this);
|
||||
}
|
||||
},
|
||||
existingData ? existingData : undefined
|
||||
// existingData ? existingData : undefined
|
||||
);
|
||||
} catch (err) {
|
||||
console.error("Could not read %s: %s", this.targetPath, err);
|
||||
|
Reference in New Issue
Block a user