electron-dl-manager
Advanced tools
Comparing version 2.3.0 to 2.3.1
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createMockDownloadData = exports.DownloadData = void 0; | ||
const events_1 = require("events"); | ||
const node_events_1 = require("node:events"); | ||
const index_1 = require("../index"); | ||
@@ -10,7 +10,7 @@ exports.DownloadData = jest.fn().mockImplementation(() => { | ||
function createMockDownloadData() { | ||
const itemEmitter = new events_1.EventEmitter(); | ||
const itemEmitter = new node_events_1.EventEmitter(); | ||
const item = { | ||
setSaveDialogOptions: jest.fn(), | ||
setSavePath: jest.fn(), | ||
getSavePath: jest.fn().mockReturnValue('/path/to/save'), | ||
getSavePath: jest.fn().mockReturnValue("/path/to/save"), | ||
getReceivedBytes: jest.fn().mockReturnValue(900), | ||
@@ -23,3 +23,3 @@ getTotalBytes: jest.fn().mockReturnValue(1000), | ||
getState: jest.fn(), | ||
getFilename: jest.fn().mockReturnValue('filename.txt'), | ||
getFilename: jest.fn().mockReturnValue("filename.txt"), | ||
// @ts-ignore | ||
@@ -26,0 +26,0 @@ on: itemEmitter.on.bind(itemEmitter), |
@@ -22,3 +22,3 @@ "use strict"; | ||
if (callbacks.onDownloadStarted) { | ||
this.log(`Calling onDownloadStarted`); | ||
this.log("Calling onDownloadStarted"); | ||
try { | ||
@@ -36,3 +36,3 @@ await callbacks.onDownloadStarted(downloadData); | ||
if (callbacks.onDownloadCompleted) { | ||
this.log(`Calling onDownloadCompleted`); | ||
this.log("Calling onDownloadCompleted"); | ||
try { | ||
@@ -63,3 +63,3 @@ await callbacks.onDownloadCompleted(downloadData); | ||
if (callbacks.onDownloadCancelled) { | ||
this.log(`Calling onDownloadCancelled`); | ||
this.log("Calling onDownloadCancelled"); | ||
try { | ||
@@ -77,3 +77,3 @@ await callbacks.onDownloadCancelled(downloadData); | ||
if (callbacks.onDownloadInterrupted) { | ||
this.log(`Calling onDownloadInterrupted`); | ||
this.log("Calling onDownloadInterrupted"); | ||
try { | ||
@@ -80,0 +80,0 @@ await callbacks.onDownloadInterrupted(downloadData); |
@@ -55,3 +55,3 @@ "use strict"; | ||
this.id = (0, utils_1.generateRandomId)(); | ||
this.resolvedFilename = 'testFile.txt'; | ||
this.resolvedFilename = "testFile.txt"; | ||
this.percentCompleted = 0; | ||
@@ -66,12 +66,12 @@ this.cancelledFromSaveAsDialog = false; | ||
isDownloadInProgress() { | ||
return this.item.getState() === 'progressing'; | ||
return this.item.getState() === "progressing"; | ||
} | ||
isDownloadCompleted() { | ||
return this.item.getState() === 'completed'; | ||
return this.item.getState() === "completed"; | ||
} | ||
isDownloadCancelled() { | ||
return this.item.getState() === 'cancelled'; | ||
return this.item.getState() === "cancelled"; | ||
} | ||
isDownloadInterrupted() { | ||
return this.item.getState() === 'interrupted'; | ||
return this.item.getState() === "interrupted"; | ||
} | ||
@@ -78,0 +78,0 @@ isDownloadResumable() { |
@@ -27,6 +27,6 @@ "use strict"; | ||
exports.DownloadInitiator = void 0; | ||
const path = __importStar(require("path")); | ||
const path = __importStar(require("node:path")); | ||
const CallbackDispatcher_1 = require("./CallbackDispatcher"); | ||
const DownloadData_1 = require("./DownloadData"); | ||
const utils_1 = require("./utils"); | ||
const DownloadData_1 = require("./DownloadData"); | ||
const CallbackDispatcher_1 = require("./CallbackDispatcher"); | ||
class DownloadInitiator { | ||
@@ -102,3 +102,3 @@ logger; | ||
initSaveAsInteractiveDownload() { | ||
this.log(`Prompting save as dialog`); | ||
this.log("Prompting save as dialog"); | ||
const { directory, overwrite, saveDialogOptions } = this.config; | ||
@@ -122,3 +122,3 @@ const { item } = this.downloadData; | ||
this.log(`User selected save path to ${this.downloadData.item.getSavePath()}`); | ||
this.log(`Initiating download item handlers`); | ||
this.log("Initiating download item handlers"); | ||
this.downloadData.resolvedFilename = path.basename(item.getSavePath()); | ||
@@ -132,4 +132,4 @@ await this.callbackDispatcher.onDownloadStarted(this.downloadData); | ||
else { | ||
item.on('updated', this.generateItemOnUpdated()); | ||
item.once('done', this.generateItemOnDone()); | ||
item.on("updated", this.generateItemOnUpdated()); | ||
item.once("done", this.generateItemOnDone()); | ||
} | ||
@@ -140,3 +140,3 @@ item.resume(); | ||
clearInterval(interval); | ||
this.log(`Download was cancelled by user`); | ||
this.log("Download was cancelled by user"); | ||
this.downloadData.cancelledFromSaveAsDialog = true; | ||
@@ -146,3 +146,3 @@ await this.callbackDispatcher.onDownloadCancelled(this.downloadData); | ||
else { | ||
this.log(`Waiting for save path to be chosen by user`); | ||
this.log("Waiting for save path to be chosen by user"); | ||
} | ||
@@ -160,7 +160,7 @@ }, 1000); | ||
item.setSavePath(filePath); | ||
this.log(`Initiating download item handlers`); | ||
this.log("Initiating download item handlers"); | ||
this.downloadData.resolvedFilename = path.basename(filePath); | ||
await this.callbackDispatcher.onDownloadStarted(this.downloadData); | ||
item.on('updated', this.generateItemOnUpdated()); | ||
item.once('done', this.generateItemOnDone()); | ||
item.on("updated", this.generateItemOnUpdated()); | ||
item.once("done", this.generateItemOnDone()); | ||
item.resume(); | ||
@@ -190,3 +190,3 @@ } | ||
switch (state) { | ||
case 'progressing': { | ||
case "progressing": { | ||
this.updateProgress(); | ||
@@ -196,4 +196,4 @@ await this.callbackDispatcher.onDownloadProgress(this.downloadData); | ||
} | ||
case 'interrupted': { | ||
this.downloadData.interruptedVia = 'in-progress'; | ||
case "interrupted": { | ||
this.downloadData.interruptedVia = "in-progress"; | ||
await this.callbackDispatcher.onDownloadInterrupted(this.downloadData); | ||
@@ -213,11 +213,11 @@ break; | ||
switch (state) { | ||
case 'completed': { | ||
case "completed": { | ||
await this.callbackDispatcher.onDownloadCompleted(this.downloadData); | ||
break; | ||
} | ||
case 'cancelled': | ||
case "cancelled": | ||
await this.callbackDispatcher.onDownloadCancelled(this.downloadData); | ||
break; | ||
case 'interrupted': | ||
this.downloadData.interruptedVia = 'completed'; | ||
case "interrupted": | ||
this.downloadData.interruptedVia = "completed"; | ||
await this.callbackDispatcher.onDownloadInterrupted(this.downloadData); | ||
@@ -234,4 +234,4 @@ break; | ||
if (item) { | ||
item.removeListener('updated', this.onItemUpdated); | ||
item.removeListener('done', this.onItemDone); | ||
item.removeListener("updated", this.onItemUpdated); | ||
item.removeListener("done", this.onItemDone); | ||
} | ||
@@ -238,0 +238,0 @@ if (this.onCleanup) { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ElectronDownloadManager = void 0; | ||
const DownloadInitiator_1 = require("./DownloadInitiator"); | ||
const utils_1 = require("./utils"); | ||
const DownloadInitiator_1 = require("./DownloadInitiator"); | ||
/** | ||
@@ -78,3 +78,3 @@ * Enables handling downloads in Electron. | ||
if (params.saveAsFilename && params.saveDialogOptions) { | ||
throw new Error('You cannot define both saveAsFilename and saveDialogOptions to start a download'); | ||
throw new Error("You cannot define both saveAsFilename and saveDialogOptions to start a download"); | ||
} | ||
@@ -88,3 +88,3 @@ const downloadInitiator = new DownloadInitiator_1.DownloadInitiator({ | ||
this.log(`[${downloadInitiator.getDownloadId()}] Registering download for url: ${(0, utils_1.truncateUrl)(params.url)}`); | ||
params.window.webContents.session.once('will-download', downloadInitiator.generateOnWillDownload(params)); | ||
params.window.webContents.session.once("will-download", downloadInitiator.generateOnWillDownload(params)); | ||
params.window.webContents.downloadURL(params.url, params.downloadURLOptions); | ||
@@ -109,4 +109,4 @@ const downloadId = downloadInitiator.getDownloadId(); | ||
dbg.attach(); | ||
await dbg.sendCommand('Network.enable'); | ||
await dbg.sendCommand('Network.emulateNetworkConditions', conditions); | ||
await dbg.sendCommand("Network.enable"); | ||
await dbg.sendCommand("Network.emulateNetworkConditions", conditions); | ||
} | ||
@@ -119,4 +119,4 @@ /** | ||
dbg.attach(); | ||
await dbg.sendCommand('Network.enable'); | ||
await dbg.sendCommand('Network.emulateNetworkConditions', { | ||
await dbg.sendCommand("Network.enable"); | ||
await dbg.sendCommand("Network.emulateNetworkConditions", { | ||
offline: false, | ||
@@ -123,0 +123,0 @@ downloadThroughput: -1, |
"use strict"; | ||
/* eslint-disable @typescript-eslint/no-unused-vars */ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -12,3 +11,3 @@ exports.ElectronDownloadManagerMock = void 0; | ||
download(_params) { | ||
return 'mock-download-id'; | ||
return "mock-download-id"; | ||
} | ||
@@ -15,0 +14,0 @@ cancelDownload(_id) { } |
@@ -7,10 +7,10 @@ "use strict"; | ||
exports.calculateDownloadMetrics = exports.determineFilePath = exports.getFilenameFromMime = exports.generateRandomId = exports.truncateUrl = void 0; | ||
const crypto_1 = __importDefault(require("crypto")); | ||
const node_crypto_1 = __importDefault(require("node:crypto")); | ||
const node_path_1 = __importDefault(require("node:path")); | ||
const electron_1 = require("electron"); | ||
const ext_name_1 = __importDefault(require("ext-name")); | ||
const electron_1 = require("electron"); | ||
const path_1 = __importDefault(require("path")); | ||
const unused_filename_1 = __importDefault(require("unused-filename")); | ||
function truncateUrl(url) { | ||
if (url.length > 50) { | ||
return url.slice(0, 50) + '...'; | ||
return `${url.slice(0, 50)}...`; | ||
} | ||
@@ -24,5 +24,5 @@ return url; | ||
const combinedValue = currentTime.toString() + randomNum.toString(); | ||
const hash = crypto_1.default.createHash('sha256'); | ||
const hash = node_crypto_1.default.createHash("sha256"); | ||
hash.update(combinedValue); | ||
return hash.digest('hex').substring(0, 6); | ||
return hash.digest("hex").substring(0, 6); | ||
} | ||
@@ -44,14 +44,14 @@ exports.generateRandomId = generateRandomId; | ||
// Code adapted from https://github.com/sindresorhus/electron-dl/blob/main/index.js#L73 | ||
if (directory && !path_1.default.isAbsolute(directory)) { | ||
throw new Error('The `directory` option must be an absolute path'); | ||
if (directory && !node_path_1.default.isAbsolute(directory)) { | ||
throw new Error("The `directory` option must be an absolute path"); | ||
} | ||
directory = directory || electron_1.app?.getPath('downloads'); | ||
directory = directory || electron_1.app?.getPath("downloads"); | ||
let filePath; | ||
if (saveAsFilename) { | ||
filePath = path_1.default.join(directory, saveAsFilename); | ||
filePath = node_path_1.default.join(directory, saveAsFilename); | ||
} | ||
else { | ||
const filename = item.getFilename(); | ||
const name = path_1.default.extname(filename) ? filename : getFilenameFromMime(filename, item.getMimeType()); | ||
filePath = overwrite ? path_1.default.join(directory, name) : unused_filename_1.default.sync(path_1.default.join(directory, name)); | ||
const name = node_path_1.default.extname(filename) ? filename : getFilenameFromMime(filename, item.getMimeType()); | ||
filePath = overwrite ? node_path_1.default.join(directory, name) : unused_filename_1.default.sync(node_path_1.default.join(directory, name)); | ||
} | ||
@@ -81,3 +81,3 @@ return filePath; | ||
} | ||
const percentCompleted = totalBytes > 0 ? Math.min(parseFloat(((downloadedBytes / totalBytes) * 100).toFixed(2)), 100) : 0; | ||
const percentCompleted = totalBytes > 0 ? Math.min(Number.parseFloat(((downloadedBytes / totalBytes) * 100).toFixed(2)), 100) : 0; | ||
return { | ||
@@ -84,0 +84,0 @@ percentCompleted, |
@@ -1,3 +0,3 @@ | ||
import { EventEmitter } from 'events'; | ||
import { generateRandomId } from '../index'; | ||
import { EventEmitter } from "node:events"; | ||
import { generateRandomId } from "../index"; | ||
export const DownloadData = jest.fn().mockImplementation(() => { | ||
@@ -11,3 +11,3 @@ return createMockDownloadData().downloadData; | ||
setSavePath: jest.fn(), | ||
getSavePath: jest.fn().mockReturnValue('/path/to/save'), | ||
getSavePath: jest.fn().mockReturnValue("/path/to/save"), | ||
getReceivedBytes: jest.fn().mockReturnValue(900), | ||
@@ -20,3 +20,3 @@ getTotalBytes: jest.fn().mockReturnValue(1000), | ||
getState: jest.fn(), | ||
getFilename: jest.fn().mockReturnValue('filename.txt'), | ||
getFilename: jest.fn().mockReturnValue("filename.txt"), | ||
// @ts-ignore | ||
@@ -23,0 +23,0 @@ on: itemEmitter.on.bind(itemEmitter), |
@@ -1,3 +0,3 @@ | ||
import { CallbackDispatcher } from './CallbackDispatcher'; | ||
import { DownloadData } from './DownloadData'; | ||
import { CallbackDispatcher } from "./CallbackDispatcher"; | ||
import { DownloadData } from "./DownloadData"; | ||
export const DownloadInitiator = jest.fn().mockImplementation(() => { | ||
@@ -4,0 +4,0 @@ return { |
@@ -19,3 +19,3 @@ /** | ||
if (callbacks.onDownloadStarted) { | ||
this.log(`Calling onDownloadStarted`); | ||
this.log("Calling onDownloadStarted"); | ||
try { | ||
@@ -33,3 +33,3 @@ await callbacks.onDownloadStarted(downloadData); | ||
if (callbacks.onDownloadCompleted) { | ||
this.log(`Calling onDownloadCompleted`); | ||
this.log("Calling onDownloadCompleted"); | ||
try { | ||
@@ -60,3 +60,3 @@ await callbacks.onDownloadCompleted(downloadData); | ||
if (callbacks.onDownloadCancelled) { | ||
this.log(`Calling onDownloadCancelled`); | ||
this.log("Calling onDownloadCancelled"); | ||
try { | ||
@@ -74,3 +74,3 @@ await callbacks.onDownloadCancelled(downloadData); | ||
if (callbacks.onDownloadInterrupted) { | ||
this.log(`Calling onDownloadInterrupted`); | ||
this.log("Calling onDownloadInterrupted"); | ||
try { | ||
@@ -77,0 +77,0 @@ await callbacks.onDownloadInterrupted(downloadData); |
@@ -1,2 +0,2 @@ | ||
import { generateRandomId } from './utils'; | ||
import { generateRandomId } from "./utils"; | ||
/** | ||
@@ -52,3 +52,3 @@ * Contains the data for a download. | ||
this.id = generateRandomId(); | ||
this.resolvedFilename = 'testFile.txt'; | ||
this.resolvedFilename = "testFile.txt"; | ||
this.percentCompleted = 0; | ||
@@ -63,12 +63,12 @@ this.cancelledFromSaveAsDialog = false; | ||
isDownloadInProgress() { | ||
return this.item.getState() === 'progressing'; | ||
return this.item.getState() === "progressing"; | ||
} | ||
isDownloadCompleted() { | ||
return this.item.getState() === 'completed'; | ||
return this.item.getState() === "completed"; | ||
} | ||
isDownloadCancelled() { | ||
return this.item.getState() === 'cancelled'; | ||
return this.item.getState() === "cancelled"; | ||
} | ||
isDownloadInterrupted() { | ||
return this.item.getState() === 'interrupted'; | ||
return this.item.getState() === "interrupted"; | ||
} | ||
@@ -75,0 +75,0 @@ isDownloadResumable() { |
@@ -1,5 +0,5 @@ | ||
import * as path from 'path'; | ||
import { calculateDownloadMetrics, determineFilePath } from './utils'; | ||
import { DownloadData } from './DownloadData'; | ||
import { CallbackDispatcher } from './CallbackDispatcher'; | ||
import * as path from "node:path"; | ||
import { CallbackDispatcher } from "./CallbackDispatcher"; | ||
import { DownloadData } from "./DownloadData"; | ||
import { calculateDownloadMetrics, determineFilePath } from "./utils"; | ||
export class DownloadInitiator { | ||
@@ -75,3 +75,3 @@ logger; | ||
initSaveAsInteractiveDownload() { | ||
this.log(`Prompting save as dialog`); | ||
this.log("Prompting save as dialog"); | ||
const { directory, overwrite, saveDialogOptions } = this.config; | ||
@@ -95,3 +95,3 @@ const { item } = this.downloadData; | ||
this.log(`User selected save path to ${this.downloadData.item.getSavePath()}`); | ||
this.log(`Initiating download item handlers`); | ||
this.log("Initiating download item handlers"); | ||
this.downloadData.resolvedFilename = path.basename(item.getSavePath()); | ||
@@ -105,4 +105,4 @@ await this.callbackDispatcher.onDownloadStarted(this.downloadData); | ||
else { | ||
item.on('updated', this.generateItemOnUpdated()); | ||
item.once('done', this.generateItemOnDone()); | ||
item.on("updated", this.generateItemOnUpdated()); | ||
item.once("done", this.generateItemOnDone()); | ||
} | ||
@@ -113,3 +113,3 @@ item.resume(); | ||
clearInterval(interval); | ||
this.log(`Download was cancelled by user`); | ||
this.log("Download was cancelled by user"); | ||
this.downloadData.cancelledFromSaveAsDialog = true; | ||
@@ -119,3 +119,3 @@ await this.callbackDispatcher.onDownloadCancelled(this.downloadData); | ||
else { | ||
this.log(`Waiting for save path to be chosen by user`); | ||
this.log("Waiting for save path to be chosen by user"); | ||
} | ||
@@ -133,7 +133,7 @@ }, 1000); | ||
item.setSavePath(filePath); | ||
this.log(`Initiating download item handlers`); | ||
this.log("Initiating download item handlers"); | ||
this.downloadData.resolvedFilename = path.basename(filePath); | ||
await this.callbackDispatcher.onDownloadStarted(this.downloadData); | ||
item.on('updated', this.generateItemOnUpdated()); | ||
item.once('done', this.generateItemOnDone()); | ||
item.on("updated", this.generateItemOnUpdated()); | ||
item.once("done", this.generateItemOnDone()); | ||
item.resume(); | ||
@@ -163,3 +163,3 @@ } | ||
switch (state) { | ||
case 'progressing': { | ||
case "progressing": { | ||
this.updateProgress(); | ||
@@ -169,4 +169,4 @@ await this.callbackDispatcher.onDownloadProgress(this.downloadData); | ||
} | ||
case 'interrupted': { | ||
this.downloadData.interruptedVia = 'in-progress'; | ||
case "interrupted": { | ||
this.downloadData.interruptedVia = "in-progress"; | ||
await this.callbackDispatcher.onDownloadInterrupted(this.downloadData); | ||
@@ -186,11 +186,11 @@ break; | ||
switch (state) { | ||
case 'completed': { | ||
case "completed": { | ||
await this.callbackDispatcher.onDownloadCompleted(this.downloadData); | ||
break; | ||
} | ||
case 'cancelled': | ||
case "cancelled": | ||
await this.callbackDispatcher.onDownloadCancelled(this.downloadData); | ||
break; | ||
case 'interrupted': | ||
this.downloadData.interruptedVia = 'completed'; | ||
case "interrupted": | ||
this.downloadData.interruptedVia = "completed"; | ||
await this.callbackDispatcher.onDownloadInterrupted(this.downloadData); | ||
@@ -207,4 +207,4 @@ break; | ||
if (item) { | ||
item.removeListener('updated', this.onItemUpdated); | ||
item.removeListener('done', this.onItemDone); | ||
item.removeListener("updated", this.onItemUpdated); | ||
item.removeListener("done", this.onItemDone); | ||
} | ||
@@ -211,0 +211,0 @@ if (this.onCleanup) { |
@@ -1,3 +0,3 @@ | ||
import { truncateUrl } from './utils'; | ||
import { DownloadInitiator } from './DownloadInitiator'; | ||
import { DownloadInitiator } from "./DownloadInitiator"; | ||
import { truncateUrl } from "./utils"; | ||
/** | ||
@@ -75,3 +75,3 @@ * Enables handling downloads in Electron. | ||
if (params.saveAsFilename && params.saveDialogOptions) { | ||
throw new Error('You cannot define both saveAsFilename and saveDialogOptions to start a download'); | ||
throw new Error("You cannot define both saveAsFilename and saveDialogOptions to start a download"); | ||
} | ||
@@ -85,3 +85,3 @@ const downloadInitiator = new DownloadInitiator({ | ||
this.log(`[${downloadInitiator.getDownloadId()}] Registering download for url: ${truncateUrl(params.url)}`); | ||
params.window.webContents.session.once('will-download', downloadInitiator.generateOnWillDownload(params)); | ||
params.window.webContents.session.once("will-download", downloadInitiator.generateOnWillDownload(params)); | ||
params.window.webContents.downloadURL(params.url, params.downloadURLOptions); | ||
@@ -106,4 +106,4 @@ const downloadId = downloadInitiator.getDownloadId(); | ||
dbg.attach(); | ||
await dbg.sendCommand('Network.enable'); | ||
await dbg.sendCommand('Network.emulateNetworkConditions', conditions); | ||
await dbg.sendCommand("Network.enable"); | ||
await dbg.sendCommand("Network.emulateNetworkConditions", conditions); | ||
} | ||
@@ -116,4 +116,4 @@ /** | ||
dbg.attach(); | ||
await dbg.sendCommand('Network.enable'); | ||
await dbg.sendCommand('Network.emulateNetworkConditions', { | ||
await dbg.sendCommand("Network.enable"); | ||
await dbg.sendCommand("Network.emulateNetworkConditions", { | ||
offline: false, | ||
@@ -120,0 +120,0 @@ downloadThroughput: -1, |
@@ -1,3 +0,2 @@ | ||
/* eslint-disable @typescript-eslint/no-unused-vars */ | ||
import { DownloadData } from './DownloadData'; | ||
import { DownloadData } from "./DownloadData"; | ||
/** | ||
@@ -9,3 +8,3 @@ * Mock version of ElectronDownloadManager | ||
download(_params) { | ||
return 'mock-download-id'; | ||
return "mock-download-id"; | ||
} | ||
@@ -12,0 +11,0 @@ cancelDownload(_id) { } |
@@ -1,10 +0,10 @@ | ||
export * from './types'; | ||
export * from './ElectronDownloadManager'; | ||
export * from './CallbackDispatcher'; | ||
export * from './DownloadData'; | ||
export * from './DownloadInitiator'; | ||
export * from './ElectronDownloadManagerMock'; | ||
export { getFilenameFromMime } from './utils'; | ||
export { generateRandomId } from './utils'; | ||
export { truncateUrl } from './utils'; | ||
export * from "./types"; | ||
export * from "./ElectronDownloadManager"; | ||
export * from "./CallbackDispatcher"; | ||
export * from "./DownloadData"; | ||
export * from "./DownloadInitiator"; | ||
export * from "./ElectronDownloadManagerMock"; | ||
export { getFilenameFromMime } from "./utils"; | ||
export { generateRandomId } from "./utils"; | ||
export { truncateUrl } from "./utils"; | ||
//# sourceMappingURL=index.js.map |
@@ -1,9 +0,9 @@ | ||
import crypto from 'crypto'; | ||
import extName from 'ext-name'; | ||
import { app } from 'electron'; | ||
import path from 'path'; | ||
import UnusedFilename from 'unused-filename'; | ||
import crypto from "node:crypto"; | ||
import path from "node:path"; | ||
import { app } from "electron"; | ||
import extName from "ext-name"; | ||
import UnusedFilename from "unused-filename"; | ||
export function truncateUrl(url) { | ||
if (url.length > 50) { | ||
return url.slice(0, 50) + '...'; | ||
return `${url.slice(0, 50)}...`; | ||
} | ||
@@ -16,5 +16,5 @@ return url; | ||
const combinedValue = currentTime.toString() + randomNum.toString(); | ||
const hash = crypto.createHash('sha256'); | ||
const hash = crypto.createHash("sha256"); | ||
hash.update(combinedValue); | ||
return hash.digest('hex').substring(0, 6); | ||
return hash.digest("hex").substring(0, 6); | ||
} | ||
@@ -35,5 +35,5 @@ // Copied from https://github.com/sindresorhus/electron-dl/blob/main/index.js#L10 | ||
if (directory && !path.isAbsolute(directory)) { | ||
throw new Error('The `directory` option must be an absolute path'); | ||
throw new Error("The `directory` option must be an absolute path"); | ||
} | ||
directory = directory || app?.getPath('downloads'); | ||
directory = directory || app?.getPath("downloads"); | ||
let filePath; | ||
@@ -70,3 +70,3 @@ if (saveAsFilename) { | ||
} | ||
const percentCompleted = totalBytes > 0 ? Math.min(parseFloat(((downloadedBytes / totalBytes) * 100).toFixed(2)), 100) : 0; | ||
const percentCompleted = totalBytes > 0 ? Math.min(Number.parseFloat(((downloadedBytes / totalBytes) * 100).toFixed(2)), 100) : 0; | ||
return { | ||
@@ -73,0 +73,0 @@ percentCompleted, |
/// <reference types="jest" /> | ||
/// <reference types="node" /> | ||
import { EventEmitter } from 'events'; | ||
import { DownloadData as ActualDownloadData } from '../index'; | ||
import { EventEmitter } from "node:events"; | ||
import { type DownloadData as ActualDownloadData } from "../index"; | ||
export declare const DownloadData: jest.Mock<any, any, any>; | ||
@@ -6,0 +6,0 @@ export declare function createMockDownloadData(): { |
@@ -1,3 +0,3 @@ | ||
import { DebugLoggerFn, DownloadManagerCallbacks } from './types'; | ||
import { DownloadData } from './DownloadData'; | ||
import type { DownloadData } from "./DownloadData"; | ||
import type { DebugLoggerFn, DownloadManagerCallbacks } from "./types"; | ||
/** | ||
@@ -4,0 +4,0 @@ * Wraps around the callbacks to handle errors and logging |
@@ -1,2 +0,2 @@ | ||
import type { DownloadItem, Event, WebContents } from 'electron'; | ||
import type { DownloadItem, Event, WebContents } from "electron"; | ||
/** | ||
@@ -49,3 +49,3 @@ * Contains the data for a download. | ||
*/ | ||
interruptedVia?: 'in-progress' | 'completed'; | ||
interruptedVia?: "in-progress" | "completed"; | ||
constructor(); | ||
@@ -52,0 +52,0 @@ isDownloadInProgress(): boolean; |
@@ -1,4 +0,4 @@ | ||
import type { DownloadItem, Event, SaveDialogOptions, WebContents } from 'electron'; | ||
import { DownloadManagerCallbacks } from './types'; | ||
import { DownloadData } from './DownloadData'; | ||
import type { DownloadItem, Event, SaveDialogOptions, WebContents } from "electron"; | ||
import { DownloadData } from "./DownloadData"; | ||
import type { DownloadManagerCallbacks } from "./types"; | ||
interface DownloadInitiatorConstructorParams { | ||
@@ -88,9 +88,9 @@ debugLogger?: (message: string) => void; | ||
*/ | ||
protected generateItemOnUpdated(): (_event: Event, state: 'progressing' | 'interrupted') => Promise<void>; | ||
protected generateItemOnUpdated(): (_event: Event, state: "progressing" | "interrupted") => Promise<void>; | ||
/** | ||
* Generates the handler for hooking into the DownloadItem's `done` event. | ||
*/ | ||
protected generateItemOnDone(): (_event: Event, state: 'completed' | 'cancelled' | 'interrupted') => Promise<void>; | ||
protected generateItemOnDone(): (_event: Event, state: "completed" | "cancelled" | "interrupted") => Promise<void>; | ||
protected cleanup(): void; | ||
} | ||
export {}; |
@@ -1,4 +0,4 @@ | ||
import type { BrowserWindow } from 'electron'; | ||
import { DownloadManagerConstructorParams, DownloadConfig, IElectronDownloadManager, DebugLoggerFn } from './types'; | ||
import { DownloadData } from './DownloadData'; | ||
import type { BrowserWindow } from "electron"; | ||
import type { DownloadData } from "./DownloadData"; | ||
import type { DebugLoggerFn, DownloadConfig, DownloadManagerConstructorParams, IElectronDownloadManager } from "./types"; | ||
/** | ||
@@ -5,0 +5,0 @@ * Enables handling downloads in Electron. |
@@ -1,3 +0,3 @@ | ||
import { DownloadConfig, IElectronDownloadManager } from './types'; | ||
import { DownloadData } from './DownloadData'; | ||
import { DownloadData } from "./DownloadData"; | ||
import type { DownloadConfig, IElectronDownloadManager } from "./types"; | ||
/** | ||
@@ -4,0 +4,0 @@ * Mock version of ElectronDownloadManager |
@@ -1,9 +0,9 @@ | ||
export * from './types'; | ||
export * from './ElectronDownloadManager'; | ||
export * from './CallbackDispatcher'; | ||
export * from './DownloadData'; | ||
export * from './DownloadInitiator'; | ||
export * from './ElectronDownloadManagerMock'; | ||
export { getFilenameFromMime } from './utils'; | ||
export { generateRandomId } from './utils'; | ||
export { truncateUrl } from './utils'; | ||
export * from "./types"; | ||
export * from "./ElectronDownloadManager"; | ||
export * from "./CallbackDispatcher"; | ||
export * from "./DownloadData"; | ||
export * from "./DownloadInitiator"; | ||
export * from "./ElectronDownloadManagerMock"; | ||
export { getFilenameFromMime } from "./utils"; | ||
export { generateRandomId } from "./utils"; | ||
export { truncateUrl } from "./utils"; |
@@ -1,3 +0,3 @@ | ||
import type { SaveDialogOptions, BrowserWindow } from 'electron'; | ||
import { DownloadData } from './DownloadData'; | ||
import type { BrowserWindow, SaveDialogOptions } from "electron"; | ||
import type { DownloadData } from "./DownloadData"; | ||
/** | ||
@@ -4,0 +4,0 @@ * The download has started |
@@ -1,2 +0,2 @@ | ||
import { DownloadItem } from 'electron'; | ||
import { type DownloadItem } from "electron"; | ||
export declare function truncateUrl(url: string): string; | ||
@@ -13,3 +13,3 @@ export declare function generateRandomId(): string; | ||
overwrite?: boolean; | ||
}): any; | ||
}): string; | ||
/** | ||
@@ -16,0 +16,0 @@ * Calculates the download rate and estimated time remaining, using the start time and current time to determine elapsed time. |
{ | ||
"name": "electron-dl-manager", | ||
"version": "2.3.0", | ||
"version": "2.3.1", | ||
"description": "A library for implementing file downloads in Electron with 'save as' dialog and id support.", | ||
@@ -10,5 +10,3 @@ "main": "dist/cjs/index.js", | ||
"scripts": { | ||
"_postinstall": "husky install", | ||
"prepublishOnly": "pinst --disable && npm run clean && npm run test && npm run build", | ||
"postpublish": "pinst --enable", | ||
"prepublishOnly": "npm run clean && npm run test && npm run lint && npm run build", | ||
"build": "npm run build:cjs && npm run build:esm && npm run build:umd && npm run build:types", | ||
@@ -21,5 +19,7 @@ "build:cjs": "node tools/cleanup cjs && tsc -p config/tsconfig.cjs.json", | ||
"package": "npm run build && npm pack", | ||
"format": "npx @biomejs/biome format src --write && npx @biomejs/biome format test --write", | ||
"lint": "npx @biomejs/biome lint src && npx @biomejs/biome lint test", | ||
"lint:check": "npx @biomejs/biome check --apply-unsafe src && npx @biomejs/biome check --apply-unsafe test", | ||
"test": "jest --no-cache --runInBand", | ||
"test:cov": "jest --coverage --no-cache --runInBand", | ||
"addscope": "node tools/packagejson name @tomchen/example-typescript-package" | ||
"test:cov": "jest --coverage --no-cache --runInBand" | ||
}, | ||
@@ -29,5 +29,3 @@ "publishConfig": { | ||
}, | ||
"files": [ | ||
"dist" | ||
], | ||
"files": ["dist"], | ||
"keywords": [ | ||
@@ -63,4 +61,3 @@ "electron", | ||
"devDependencies": { | ||
"@commitlint/cli": "^19.2.1", | ||
"@commitlint/config-conventional": "^19.1.0", | ||
"@biomejs/biome": "1.6.3", | ||
"@types/jest": "^29.5.12", | ||
@@ -71,9 +68,3 @@ "@typescript-eslint/eslint-plugin": "^7.3.1", | ||
"electron": "28.2.7", | ||
"eslint": "^8.57.0", | ||
"eslint-config-prettier": "^8.10.0", | ||
"eslint-plugin-prettier": "^5.1.3", | ||
"husky": "^7.0.2", | ||
"jest": "^29.7.0", | ||
"pinst": "^2.1.6", | ||
"prettier": "^3.2.5", | ||
"ts-jest": "^29.1.2", | ||
@@ -80,0 +71,0 @@ "ts-loader": "^9.5.1", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
288967
12
1902