@aj-archipelago/cortex 1.1.27 → 1.1.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/helper-apps/cortex-file-handler/blobHandler.js +24 -3
- package/helper-apps/cortex-file-handler/dump.rdb +0 -0
- package/helper-apps/cortex-file-handler/fileChunker.js +2 -1
- package/helper-apps/cortex-file-handler/package-lock.json +10 -10
- package/helper-apps/cortex-file-handler/package.json +1 -1
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import fs from "fs";
|
|
2
2
|
import path from "path";
|
|
3
|
-
import { BlobServiceClient } from "@azure/storage-blob";
|
|
3
|
+
import { generateBlobSASQueryParameters, StorageSharedKeyCredential, BlobServiceClient } from "@azure/storage-blob";
|
|
4
4
|
import { v4 as uuidv4 } from "uuid";
|
|
5
5
|
import Busboy from "busboy";
|
|
6
6
|
import { PassThrough } from "stream";
|
|
@@ -53,6 +53,7 @@ function isBase64(str) {
|
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
+
const { SAS_TOKEN_LIFE_DAYS = 30 } = process.env;
|
|
56
57
|
const GCP_SERVICE_ACCOUNT_KEY =
|
|
57
58
|
process.env.GCP_SERVICE_ACCOUNT_KEY_BASE64 ||
|
|
58
59
|
process.env.GCP_SERVICE_ACCOUNT_KEY ||
|
|
@@ -138,6 +139,7 @@ async function saveFileToBlob(chunkPath, requestId) {
|
|
|
138
139
|
const { containerClient } = await getBlobClient();
|
|
139
140
|
// Use the filename with a UUID as the blob name
|
|
140
141
|
const blobName = `${requestId}/${uuidv4()}_${encodeURIComponent(path.basename(chunkPath))}`;
|
|
142
|
+
const sasToken = generateSASToken(containerClient, blobName);
|
|
141
143
|
|
|
142
144
|
// Create a read stream for the chunk file
|
|
143
145
|
const fileStream = fs.createReadStream(chunkPath);
|
|
@@ -147,10 +149,28 @@ async function saveFileToBlob(chunkPath, requestId) {
|
|
|
147
149
|
await blockBlobClient.uploadStream(fileStream);
|
|
148
150
|
|
|
149
151
|
// Return the full URI of the uploaded blob
|
|
150
|
-
const blobUrl = blockBlobClient.url
|
|
152
|
+
const blobUrl = `${blockBlobClient.url}?${sasToken}`;
|
|
151
153
|
return blobUrl;
|
|
152
154
|
}
|
|
153
155
|
|
|
156
|
+
const generateSASToken = (containerClient, blobName, expiryTimeSeconds =
|
|
157
|
+
parseInt(SAS_TOKEN_LIFE_DAYS) * 24 * 60 * 60
|
|
158
|
+
) => {
|
|
159
|
+
const { accountName, accountKey } = containerClient.credential;
|
|
160
|
+
const sharedKeyCredential = new StorageSharedKeyCredential(accountName, accountKey);
|
|
161
|
+
|
|
162
|
+
const sasOptions = {
|
|
163
|
+
containerName: containerClient.containerName,
|
|
164
|
+
blobName: blobName,
|
|
165
|
+
permissions: "r", // Read permission
|
|
166
|
+
startsOn: new Date(),
|
|
167
|
+
expiresOn: new Date(new Date().valueOf() + expiryTimeSeconds * 1000)
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
const sasToken = generateBlobSASQueryParameters(sasOptions, sharedKeyCredential).toString();
|
|
171
|
+
return sasToken;
|
|
172
|
+
};
|
|
173
|
+
|
|
154
174
|
//deletes blob that has the requestId
|
|
155
175
|
async function deleteBlob(requestId) {
|
|
156
176
|
if (!requestId) throw new Error("Missing requestId parameter");
|
|
@@ -271,8 +291,9 @@ async function uploadFile(context, requestId, body, saveToLocal, useGoogle, file
|
|
|
271
291
|
await blockBlobClient.uploadStream(passThroughStream, undefined, undefined, options);
|
|
272
292
|
|
|
273
293
|
const message = `File '${encodedFilename}' uploaded successfully.`;
|
|
274
|
-
const url = blockBlobClient.url;
|
|
275
294
|
context.log(message);
|
|
295
|
+
const sasToken = generateSASToken(containerClient, encodedFilename);
|
|
296
|
+
const url = `${blockBlobClient.url}?${sasToken}`;
|
|
276
297
|
body = { message, url };
|
|
277
298
|
}
|
|
278
299
|
|
|
Binary file
|
|
@@ -118,7 +118,8 @@ const ytdlDownload = async (url, filename, video = false) => {
|
|
|
118
118
|
? { filter: 'audioandvideo' } // audio and video
|
|
119
119
|
: { quality: 'highestaudio' }; // audio only
|
|
120
120
|
|
|
121
|
-
const
|
|
121
|
+
const encodedUrl = encodeURI(url);
|
|
122
|
+
const videoStream = ytdl(encodedUrl, videoOptions);
|
|
122
123
|
let lastLoggedTime = Date.now();
|
|
123
124
|
|
|
124
125
|
videoStream.on('error', (error) => {
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"version": "1.0.0",
|
|
10
10
|
"dependencies": {
|
|
11
11
|
"@azure/storage-blob": "^12.13.0",
|
|
12
|
-
"@distube/ytdl-core": "^4.
|
|
12
|
+
"@distube/ytdl-core": "^4.14.3",
|
|
13
13
|
"@google-cloud/storage": "^7.10.0",
|
|
14
14
|
"axios": "^1.3.6",
|
|
15
15
|
"busboy": "^1.6.0",
|
|
@@ -158,19 +158,19 @@
|
|
|
158
158
|
}
|
|
159
159
|
},
|
|
160
160
|
"node_modules/@distube/ytdl-core": {
|
|
161
|
-
"version": "4.
|
|
162
|
-
"resolved": "https://registry.npmjs.org/@distube/ytdl-core/-/ytdl-core-4.
|
|
163
|
-
"integrity": "sha512-
|
|
161
|
+
"version": "4.14.3",
|
|
162
|
+
"resolved": "https://registry.npmjs.org/@distube/ytdl-core/-/ytdl-core-4.14.3.tgz",
|
|
163
|
+
"integrity": "sha512-z6i5EVGEuKhuvuRNyIqafBSs5aRA28HssnWehCRhEtYrxeFgXImfmpKTjUusHYU5vQt1swSVPVb2JCd22P0CPA==",
|
|
164
164
|
"dependencies": {
|
|
165
165
|
"http-cookie-agent": "^6.0.5",
|
|
166
166
|
"m3u8stream": "^0.8.6",
|
|
167
167
|
"miniget": "^4.2.3",
|
|
168
168
|
"sax": "^1.4.1",
|
|
169
169
|
"tough-cookie": "^4.1.4",
|
|
170
|
-
"undici": "
|
|
170
|
+
"undici": "five"
|
|
171
171
|
},
|
|
172
172
|
"engines": {
|
|
173
|
-
"node": ">=
|
|
173
|
+
"node": ">=14.0"
|
|
174
174
|
},
|
|
175
175
|
"funding": {
|
|
176
176
|
"url": "https://github.com/distubejs/ytdl-core?sponsor"
|
|
@@ -3073,16 +3073,16 @@
|
|
|
3073
3073
|
}
|
|
3074
3074
|
},
|
|
3075
3075
|
"@distube/ytdl-core": {
|
|
3076
|
-
"version": "4.
|
|
3077
|
-
"resolved": "https://registry.npmjs.org/@distube/ytdl-core/-/ytdl-core-4.
|
|
3078
|
-
"integrity": "sha512-
|
|
3076
|
+
"version": "4.14.3",
|
|
3077
|
+
"resolved": "https://registry.npmjs.org/@distube/ytdl-core/-/ytdl-core-4.14.3.tgz",
|
|
3078
|
+
"integrity": "sha512-z6i5EVGEuKhuvuRNyIqafBSs5aRA28HssnWehCRhEtYrxeFgXImfmpKTjUusHYU5vQt1swSVPVb2JCd22P0CPA==",
|
|
3079
3079
|
"requires": {
|
|
3080
3080
|
"http-cookie-agent": "^6.0.5",
|
|
3081
3081
|
"m3u8stream": "^0.8.6",
|
|
3082
3082
|
"miniget": "^4.2.3",
|
|
3083
3083
|
"sax": "^1.4.1",
|
|
3084
3084
|
"tough-cookie": "^4.1.4",
|
|
3085
|
-
"undici": "
|
|
3085
|
+
"undici": "five"
|
|
3086
3086
|
}
|
|
3087
3087
|
},
|
|
3088
3088
|
"@google-cloud/paginator": {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aj-archipelago/cortex",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.28",
|
|
4
4
|
"description": "Cortex is a GraphQL API for AI. It provides a simple, extensible interface for using AI services from OpenAI, Azure and others.",
|
|
5
5
|
"private": false,
|
|
6
6
|
"repository": {
|