diff options
author | bobzel <zzzman@gmail.com> | 2021-05-18 14:58:18 -0400 |
---|---|---|
committer | bobzel <zzzman@gmail.com> | 2021-05-18 15:50:30 -0400 |
commit | 6919954467f3f2e4ca2f02e34eda827df9f5f83d (patch) | |
tree | 3d80cefa5558d93a896a1ef6c7b98b9da83c2bde /src/client/documents/Documents.ts | |
parent | 4760f9be498d19de9d285e8d99e5fbb277df1904 (diff) |
added downloading of youtube videos if https://youtube-dl.org/ is installed on the server's path
Diffstat (limited to 'src/client/documents/Documents.ts')
-rw-r--r-- | src/client/documents/Documents.ts | 36 |
1 files changed, 23 insertions, 13 deletions
diff --git a/src/client/documents/Documents.ts b/src/client/documents/Documents.ts index 219890945..24682cbd0 100644 --- a/src/client/documents/Documents.ts +++ b/src/client/documents/Documents.ts @@ -1386,19 +1386,15 @@ export namespace DocUtils { return optionsCollection; } - export async function uploadFilesToDocs(files: File[], options: DocumentOptions) { - const generatedDocuments: Doc[] = []; - for (const { source: { name, type }, result } of await Networking.UploadFilesToServer(files)) { - if (result instanceof Error) { - alert(`Upload failed: ${result.message}`); - return []; - } - const full = { ...options, _width: 400, title: name }; - const pathname = Utils.prepend(result.accessPaths.agnostic.client); - const doc = await DocUtils.DocumentFromType(type, pathname, full); - if (!doc) { - continue; - } + async function processFileupload(generatedDocuments: Doc[], name: string, type: string, result: Error | Upload.FileInformation, options: DocumentOptions) { + if (result instanceof Error) { + alert(`Upload failed: ${result.message}`); + return; + } + const full = { ...options, _width: 400, title: name }; + const pathname = Utils.prepend(result.accessPaths.agnostic.client); + const doc = await DocUtils.DocumentFromType(type, pathname, full); + if (doc) { const proto = Doc.GetProto(doc); proto.text = result.rawText; proto.fileUpload = basename(pathname).replace("upload_", "").replace(/\.[a-z0-9]*$/, ""); @@ -1415,6 +1411,20 @@ export namespace DocUtils { } generatedDocuments.push(doc); } + } + + export async function uploadYoutubeVideo(videoId: string, options: DocumentOptions) { + const generatedDocuments: Doc[] = []; + for (const { source: { name, type }, result } of await Networking.UploadYoutubeToServer(videoId)) { + processFileupload(generatedDocuments, name, type, result, options); + } + return generatedDocuments; + } + export async function uploadFilesToDocs(files: File[], options: DocumentOptions) { + const generatedDocuments: Doc[] = []; + for (const { source: { name, type }, result } of await Networking.UploadFilesToServer(files)) { + processFileupload(generatedDocuments, name, type, result, options); + } return generatedDocuments; } } |