Skip to content

Commit

Permalink
[fix] no proxy used when downloading in viewer.
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkPoloChina committed Feb 8, 2024
1 parent f8488a5 commit 85a3af5
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,8 @@ function afterReady() {
return await FS.loadStringFromFile(filename)
})

ipcMain.handle('ds:download', async (event, url, filename, dir) => {
await DS.downloadAndSave(url, filename, dir)
ipcMain.handle('ds:download', async (event, url, filename, dir, isPixiv) => {
await DS.downloadAndSave(url, filename, dir, isPixiv)
})
ipcMain.handle('ds:downloadPixiv', async (event, illustObj, dir, page) => {
await DS.downloadFromIllustObj(illustObj, dir, page)
Expand Down
3 changes: 2 additions & 1 deletion src/main/node-processor/DownloadService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,10 @@ export class DS {
url: string,
filename: string,
dir: string,
isPixiv?: boolean,
): Promise<void> {
if (!await FS.isExists(path.join(dir, filename)))
await FS.saveArrayBufferTo(await this.downloadFromUrl(url), filename, dir)
await FS.saveArrayBufferTo(await this.downloadFromUrl(url, isPixiv), filename, dir)
}

public static async downloadFromIllustObj(
Expand Down
2 changes: 1 addition & 1 deletion src/preload/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ declare global {
params: any,
body: any
): Promise<any>;
downloadTo(url: string, rename: string, dir: string): Promise<void>;
downloadTo(url: string, rename: string, dir: string, isPixiv?: boolean): Promise<void>;
downloadPixivTo(illustObj: PixivIllust, dir: string, page?: number): Promise<void>;
downloadPixivUgoiraTo(illustObj: PixivIllust, dir: string, meta: UgoiraMetaData): Promise<void>;
};
Expand Down
4 changes: 2 additions & 2 deletions src/preload/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ contextBridge.exposeInMainWorld('electron', {
): Promise<any> => ipcRenderer.invoke(`api:${method}${url}`, params, body),

// downloader
downloadTo: (url: string, rename: string, dir: string): Promise<void> =>
ipcRenderer.invoke('ds:download', url, rename, dir),
downloadTo: (url: string, rename: string, dir: string, isPixiv = false): Promise<void> =>
ipcRenderer.invoke('ds:download', url, rename, dir, isPixiv),

downloadPixivTo: (illustObj: PixivIllust, dir: string, page?: number): Promise<void> =>
ipcRenderer.invoke('ds:downloadPixiv', illustObj, dir, page),
Expand Down
2 changes: 2 additions & 0 deletions src/render/components/icxorViewer/viewerMain.vue
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ async function handleDownload() {
? PathHelper.getBasename(url)
: currentOperating.value.remote_endpoint,
dir,
url.includes('i.pximg.net'),
)
ElMessage.success('下载完成')
}
Expand Down Expand Up @@ -328,6 +329,7 @@ async function handleDownloadBatch() {
? PathHelper.getBasename(url)
: obj.remote_endpoint,
dir,
url.includes('i.pximg.net'),
)
}
catch (err) {
Expand Down
4 changes: 2 additions & 2 deletions src/render/ts/util/path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class PathHelper {
}

export class UrlGenerator {
static getBlobUrl(obj: IllustObj, type: 'original' | 'medium' | 'large' | 'square_medium' | 's_large' = 'original') {
static getBlobUrl(obj: IllustObj, type: 'original' | 'medium' | 'large' | 'square_medium' | 's_large' = 'original'): string {
if (!serverMode && obj.remote_base.type !== 'cos')
return this.getBlobUrlLocal(obj, type)
if (obj.remote_base.type === 'pixiv') {
Expand Down Expand Up @@ -100,7 +100,7 @@ export class UrlGenerator {
}
}

static getBlobUrlLocal(obj: IllustObj, type: 'original' | 'medium' | 'large' | 'square_medium' | 's_large' = 'original') {
static getBlobUrlLocal(obj: IllustObj, type: 'original' | 'medium' | 'large' | 'square_medium' | 's_large' = 'original'): string {
if (obj.remote_base.type === 'pixiv') {
if (type === 'original' || type === 's_large') {
if (obj.remote_endpoint && local_base_map[obj.remote_base.name]?.original)
Expand Down

0 comments on commit 85a3af5

Please sign in to comment.