forked from FoundKeyGang/FoundKey
parent
8cd47bbcce
commit
9354950c23
2 changed files with 1 additions and 5 deletions
|
@ -1,4 +1,3 @@
|
||||||
import { URL } from 'node:url';
|
|
||||||
import * as fs from 'node:fs';
|
import * as fs from 'node:fs';
|
||||||
import * as stream from 'node:stream';
|
import * as stream from 'node:stream';
|
||||||
import * as util from 'node:util';
|
import * as util from 'node:util';
|
||||||
|
@ -21,7 +20,6 @@ export async function downloadUrl(url: string, path: string): Promise<void> {
|
||||||
const timeout = 30 * SECOND;
|
const timeout = 30 * SECOND;
|
||||||
const operationTimeout = MINUTE;
|
const operationTimeout = MINUTE;
|
||||||
const maxSize = config.maxFileSize || 262144000;
|
const maxSize = config.maxFileSize || 262144000;
|
||||||
let filename = new URL(url).pathname.split('/').pop() || null;
|
|
||||||
|
|
||||||
const req = got.stream(url, {
|
const req = got.stream(url, {
|
||||||
headers: {
|
headers: {
|
||||||
|
@ -53,7 +51,6 @@ export async function downloadUrl(url: string, path: string): Promise<void> {
|
||||||
}
|
}
|
||||||
|
|
||||||
const contentLength = res.headers['content-length'];
|
const contentLength = res.headers['content-length'];
|
||||||
filename = res.headers['content-disposition'].split('=').pop().replace(/"/g, '');
|
|
||||||
if (contentLength != null) {
|
if (contentLength != null) {
|
||||||
const size = Number(contentLength);
|
const size = Number(contentLength);
|
||||||
if (size > maxSize) {
|
if (size > maxSize) {
|
||||||
|
@ -79,7 +76,6 @@ export async function downloadUrl(url: string, path: string): Promise<void> {
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.succ(`Download finished: ${chalk.cyan(url)}`);
|
logger.succ(`Download finished: ${chalk.cyan(url)}`);
|
||||||
return filename;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function isPrivateIp(ip: string): boolean {
|
function isPrivateIp(ip: string): boolean {
|
||||||
|
|
|
@ -41,7 +41,7 @@ export async function uploadFromUrl({
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// write content at URL to temp file
|
// write content at URL to temp file
|
||||||
name = await downloadUrl(url, path);
|
await downloadUrl(url, path);
|
||||||
|
|
||||||
const driveFile = await addFile({
|
const driveFile = await addFile({
|
||||||
user,
|
user,
|
||||||
|
|
Loading…
Reference in a new issue