useDownload.ts
565 Bytes
import { downloadPackage } from '/@/api/ota';
import { OtaRecordDatum } from '/@/api/ota/model';
export async function useDownload(record: OtaRecordDatum) {
try {
if (record.url || !record.fileName) return;
const data = await downloadPackage(record.id.id);
const aEl = document.createElement('a');
const blob = new Blob([data], { type: record.contentType });
const objectUrl = URL.createObjectURL(blob);
aEl.href = objectUrl;
aEl.download = record.fileName;
aEl.click();
URL.revokeObjectURL(objectUrl);
} catch (error) {}
}