1import { 2 BaseStorageAudioFile, 3 BaseStorageImageFile, 4 BaseStorageVideoFile, 5 StorageAudioFile, 6 StorageFile, 7 StorageImageFile, 8 StorageVideoFile, 9 safeStringify 10} from "./chunks/chunk.OXUF5T2O.js"; 11import { 12 createSharedDownloadUrlImpl, 13 getAudioTrackHash, 14 getDownloadUrlByIdImpl, 15 getDownloadUrlImpl, 16 getDurationFromHash, 17 getFileTypeFromHash, 18 getOriginalUrlImpl, 19 getPublicFileUrlImpl, 20 getPublicThumbnailUrlImpl, 21 getSizesFromHash, 22 getThumbnailUrlByIdImpl, 23 getThumbnailUrlImpl, 24 getUploadGetPutUrlImpl 25} from "./chunks/chunk.DJMN7NEM.js"; 26import { 27 request 28} from "./chunks/chunk.SE3QUYR4.js"; 29import "./chunks/chunk.5JGUXAXZ.js"; 30import "./chunks/chunk.4FDTDPU2.js"; 31import "./chunks/chunk.IFY22QVW.js"; 32import "./chunks/chunk.PURDAWFW.js"; 33 34// src/services/ugc-runner/runtime/builtin/appStorage.ts 35var StorageFile2 = StorageFile; 36var StorageImageFile2 = StorageImageFile; 37var StorageVideoFile2 = StorageVideoFile; 38var StorageAudioFile2 = StorageAudioFile; 39function isImageFile(file) { 40 return file instanceof BaseStorageImageFile; 41} 42function isVideoFile(file) { 43 return file instanceof BaseStorageVideoFile; 44} 45function isAudioFile(file) { 46 return file instanceof BaseStorageAudioFile; 47} 48function createStorageFileFromHash(hash) { 49 if (hash instanceof StorageFile2) { 50 return hash; 51 } 52 const fileHash = typeof hash === "string" ? hash : hash.hash; 53 switch (getFileTypeFromHash(fileHash)) { 54 case "image": 55 return new StorageImageFile(fileHash); 56 case "video": 57 return new StorageVideoFile(fileHash); 58 case "audio": 59 return new StorageAudioFile(fileHash); 60 default: 61 return new StorageFile(fileHash); 62 } 63} 64function getUploadGetPutUrl(ctx, options) { 65 return getUploadGetPutUrlImpl(ctx, options ?? {}) + (options?.protected ? "?p=1" : ""); 66} 67function createUploadPutUrl(_ctx, options) { 68 return __ugc_internals__.sysCall("storage", "createUploadPutUrl", options); 69} 70async function obtainStorageFilePutUrl(ctx, options) { 71 let res; 72 await (async () => { 73 let effectiveGetPutUrl; 74 try { 75 effectiveGetPutUrl = options?.getPutUrl || getUploadGetPutUrl(ctx, options); 76 } catch (err) { 77 console.warn(`GetPutUrl is not provided: ${err}`); 78 } 79 if (effectiveGetPutUrl) { 80 const resp = await request.post(effectiveGetPutUrl); 81 if (resp.body?.data?.filePutUrl) { 82 res = resp.body.data.filePutUrl; 83 } else { 84 throw new Error(`Invalid response from getPutUrl ${effectiveGetPutUrl}: ${safeStringify(resp.body)}`); 85 } 86 } 87 })(); 88 return res || options?.filePutUrl || `${__ugc_internals__.out.fileService.fileServiceHost}/upload?accountId=${ctx.account.id}`; 89} 90function getFetchAuthUrl(ctx, fetchUrl, options) { 91 return getUploadGetPutUrlImpl(ctx, {}) + `?fetch=${encodeURIComponent(fetchUrl)}` + (options?.protected ? "&p=1" : "") + (options?.headers && Object.keys(options.headers).length > 0 ? `&h=${encodeURIComponent(JSON.stringify(options.headers))}` : ""); 92} 93function createFetchUrl(_ctx, fetchUrl, options) { 94 return __ugc_internals__.sysCall("storage", "createFetchUrl", fetchUrl, options); 95} 96async function fetchUrlToStorage(ctx, fetchUrl, options) { 97 const resp = await request.get(await createFetchUrl(ctx, fetchUrl, options), { responseType: "text" }); 98 if (!resp.body || typeof resp.body !== "string") { 99 throw new Error(`Invalid file storage response while fetching ${fetchUrl}: ${resp.body}`); 100 } 101 return resp.body; 102} 103function createPartialUploadUrl(_ctx, fileName, options) { 104 return __ugc_internals__.sysCall("storage", "createPartialUploadUrl", fileName, options); 105} 106function createPartialAppendUrl(_ctx, partialUploadHash, options) { 107 return __ugc_internals__.sysCall("storage", "createPartialAppendUrl", partialUploadHash, options); 108} 109function createPartialPublishUrl(_ctx, partialUploadHash, options) { 110 return __ugc_internals__.sysCall("storage", "createPartialPublishUrl", partialUploadHash, options); 111} 112async function startPartialStorageFileUpload(ctx, fileName, options) { 113 const resp = await request.get( 114 await createPartialUploadUrl(ctx, fileName, options) 115 ); 116 if (!resp.body.success) { 117 throw new Error(`Failed to create a partial file upload for '${fileName}'`); 118 } 119 return resp.body.hash; 120}
121async function appendToPartialStorageFile(ctx, partialUploadHash, dataChunk) { 122 const resp = await request.post( 123 await createPartialAppendUrl(ctx, partialUploadHash), 124 dataChunk 125 ); 126 if (!resp.body.success) { 127 throw new Error(`Failed to append data to the partial file '${partialUploadHash}': ${resp.body.message}`); 128 } 129} 130async function finalizePartialStorageFileUpload(ctx, partialUploadHash) { 131 const resp = await request.get( 132 await createPartialPublishUrl(ctx, partialUploadHash) 133 ); 134 if (!resp.body.success) { 135 throw new Error(`Failed to finalize the partial file upload for '${partialUploadHash}'`); 136 } 137 return resp.body.hash; 138} 139function listFiles(_ctx, options) { 140 return __ugc_internals__.sysCall("storage", "listFiles", options); 141} 142function getFilesStats(_ctx, options) { 143 return __ugc_internals__.sysCall("storage", "getFilesStats", options); 144} 145function getThumbnailUrlById(ctx, id, width, height) { 146 return getThumbnailUrlByIdImpl(ctx, id, width, height); 147} 148function getDownloadUrlById(ctx, id) { 149 return getDownloadUrlByIdImpl(ctx, id); 150} 151function getHashesByIds(_ctx, ids) { 152 return __ugc_internals__.sysCall("storage", "getHashesByIds", ids); 153} 154function getFilesUserStats(_ctx, options) { 155 return __ugc_internals__.sysCall("storage", "getFilesUserStats", options); 156} 157function getFilesMediaTypeStats(_ctx, options) { 158 return __ugc_internals__.sysCall("storage", "getFilesMediaTypeStats", options); 159} 160function getFilesAppStats(_ctx, options) { 161 return __ugc_internals__.sysCall("storage", "getFilesAppStats", options); 162} 163function createPublicCopy(_ctx, hash) { 164 return __ugc_internals__.sysCall("storage", "createPublicCopy", hash); 165} 166function deleteFileById(_ctx, id) { 167 return __ugc_internals__.sysCall("storage", "deleteFileById", id); 168} 169function deleteFileByHash(_ctx, hash) { 170 return __ugc_internals__.sysCall("storage", "deleteFileByHash", typeof hash === "string" ? hash : hash.hash); 171} 172function restoreFileById(_ctx, id) { 173 return __ugc_internals__.sysCall("storage", "restoreFileById", id); 174} 175function getVideoInfo(one, two) { 176 const haveCtx = "string" !== typeof one; 177 const ctx = haveCtx ? one : void 0; 178 const hash = haveCtx ? two : one; 179 const ctxLocation = { 180 location: ctx?.location 181 }; 182 return __ugc_internals__.out.fileService.getVideoInfo(ctxLocation, hash); 183} 184function getAudioInfo(ctx, hash) { 185 return __ugc_internals__.out.fileService.getAudioInfo({ location: ctx.location }, hash); 186} 187function getThumbnailUrl(ctx, hash, width, height) { 188 const haveCtx = !!ctx?.account; 189 return getThumbnailUrlImpl( 190 haveCtx ? ctx : void 0, 191 haveCtx ? hash : ctx, 192 haveCtx ? width : hash, 193 haveCtx ? height : width 194 ); 195} 196function getFileMeta(_ctx, hash, key) { 197 return __ugc_internals__.sysCall("storage", "getFileMeta", typeof hash === "string" ? hash : hash.hash, key); 198} 199function updateFileMeta(_ctx, hash, key, value) { 200 return __ugc_internals__.sysCall("storage", "updateFileMeta", typeof hash === "string" ? hash : hash.hash, key, value); 201} 202function makeFilePublic(_ctx, hash) { 203 return __ugc_internals__.sysCall("storage", "makeFilePublic", typeof hash === "string" ? hash : hash.hash); 204} 205function getPublicThumbnailUrl(ctx, hash, width, height) { 206 return getPublicThumbnailUrlImpl(ctx, hash, width, height); 207} 208function getPublicFileUrl(ctx, hash) { 209 return getPublicFileUrlImpl(ctx, hash); 210} 211function createSharedThumbnailUrl(ctx, hash, options) { 212 return createSharedDownloadUrlImpl(ctx, "thumbnail", hash, options); 213} 214function getDownloadUrl(ctx, hash) { 215 const haveCtx = "string" !== typeof ctx; 216 return getDownloadUrlImpl( 217 haveCtx ? ctx : void 0, 218 haveCtx ? hash : ctx 219 ); 220} 221function createSharedDownloadUrl(ctx, hash, options) { 222 return createSharedDownloadUrlImpl(ctx, "download", hash, options); 223} 224function createSharedAudioUrl(ctx, hash, options) { 225 const fileHash = "string" === typeof hash ? hash : hash.hash; 226 return createSharedDownloadUrlImpl(ctx, "original", getAudioTrackHash(fileHash), options); 227} 228function getOriginalUrl(ctx, hash) { 229 return getOriginalUrlImpl(ctx, hash); 230} 231function createSharedOriginalUrl(ctx, hash, options) { 232 return createSharedDownloadUrlImpl(ctx, "original", hash, options); 233} 234function createForwardInitUrl(_ctx, hashes, forwardUrl, options) { 235 return __ugc_internals__.sysCall("storage", "createForwardInitUrl", hashes, forwardUrl, options); 236} 237async function createForwardStatusUrl(_ctx, forwardRequestId) { 238 return `${__ugc_internals__.out.fileService.fileServiceHost}/forward?requestId=${forwardRequestId}`; 239} 240async function forwardStorageFilesToUrl(ctx, params) { 241 let hashes, files; 242 if ("files" in params) { 243 files = params.files; 244 hashes = Object.values(files); 245 } else { 246 files = { [params.fileFieldName ?? params.fileName]: params.fileHash }; 247 hashes = [params.fileHash]; 248 } 249 const res = await request.post( 250 await createForwardInitUrl(ctx, hashes, params.uploadToUrl), 251 { 252 url: params.uploadToUrl, 253 headers: params.headers, 254 files, 255 fields: params.additionalFormFields 256 } 257 ); 258 if (res.body.success !== true) { 259 throw new Error(`Failed to upload files to ${params.uploadToUrl}`); 260 } 261 return res.body.requestId; 262} 263async function checkForwardStatus(ctx, forwardRequestId) { 264 const res = await request.get(await createForwardStatusUrl(ctx, forwardRequestId)); 265 const body = res.body; 266 if ("success" in body) { 267 if (body.success === null && body.status === "forwarding") { 268 return { status: "forwarding" }; 269 } else if ("headers" in body && "data" in body) { 270 return { 271 status: body.success ? "success" : "failure", 272 responseCode: body.status, 273 responseBody: body.data, 274 responseHeaders: body.headers 275 }; 276 } else { 277 return { status: "error", reason: body.message }; 278 } 279 } else { 280 throw new Error(`Unexpected response from forward status endpoint: ${safeStringify(body)}`); 281 } 282} 283function getImageSrcFromHash(one, two, three, four) { 284 const haveCtx = typeof one !== "string" && !isStorageFileHashArg(one); 285 const ctx = haveCtx ? one : void 0; 286 let hash = haveCtx ? two ?? "" : one; 287 const width = haveCtx ? three : typeof two === "number" ? two : void 0; 288 const height = haveCtx ? four : three; 289 if (hash instanceof StorageFile2) { 290 hash = hash.hash; 291 } 292 if (width) { 293 if (height) { 294 return { 295 url: getThumbnailUrl(ctx, hash, width, height), 296 width, 297 height 298 }; 299 } else { 300 const sizes = getSizesFromHash(hash); 301 if (sizes && sizes.width && sizes.height) { 302 const adoptedHeight = sizes.height * width / sizes.width; 303 return { 304 url: getThumbnailUrl(ctx, hash, width, adoptedHeight),
305 width, 306 height: adoptedHeight 307 }; 308 } else { 309 return { url: tryGetImageUrlWithOriginSizes(ctx, hash, sizes) }; 310 } 311 } 312 } else if (height) { 313 const sizes = getSizesFromHash(hash); 314 if (sizes && sizes.width && sizes.height) { 315 const adoptedWidth = sizes.width * height / sizes.height; 316 return { 317 url: getThumbnailUrl(ctx, hash, adoptedWidth, height), 318 width: adoptedWidth, 319 height 320 }; 321 } else { 322 return { url: tryGetImageUrlWithOriginSizes(ctx, hash, sizes) }; 323 } 324 } else { 325 const sizes = getSizesFromHash(hash); 326 if (sizes && sizes.width && sizes.height) { 327 return { 328 url: tryGetImageUrlWithOriginSizes(ctx, hash, sizes), 329 width: sizes.width, 330 height: sizes.height 331 }; 332 } else { 333 return { url: tryGetImageUrlWithOriginSizes(ctx, hash, sizes) }; 334 } 335 } 336} 337function tryGetImageUrlWithOriginSizes(ctx, hash, sizes) { 338 return getFileTypeFromHash(hash) === "image" ? ( 339 // for image files we can take an original URL, because it's already an image 340 getOriginalUrl(ctx, hash) 341 ) : ( 342 // for other types we have to try a thumbnail URL to get an image 343 getThumbnailUrl(ctx, hash, sizes?.width ?? 300, sizes?.height ?? 300) 344 ); 345} 346function isStorageFileHashArg(value) { 347 if (!value || typeof value !== "object") { 348 return false; 349 } 350 return typeof value.hash === "string"; 351} 352export { 353 StorageAudioFile2 as StorageAudioFile, 354 StorageFile2 as StorageFile, 355 StorageImageFile2 as StorageImageFile, 356 StorageVideoFile2 as StorageVideoFile, 357 appendToPartialStorageFile, 358 checkForwardStatus, 359 createFetchUrl, 360 createForwardInitUrl, 361 createForwardStatusUrl, 362 createPartialAppendUrl, 363 createPartialPublishUrl, 364 createPartialUploadUrl, 365 createPublicCopy, 366 createSharedAudioUrl, 367 createSharedDownloadUrl, 368 createSharedOriginalUrl, 369 createSharedThumbnailUrl, 370 createStorageFileFromHash, 371 createUploadPutUrl, 372 deleteFileByHash, 373 deleteFileById, 374 fetchUrlToStorage, 375 finalizePartialStorageFileUpload, 376 forwardStorageFilesToUrl, 377 getAudioInfo, 378 getAudioTrackHash, 379 getDownloadUrl, 380 getDownloadUrlById, 381 getDurationFromHash, 382 getFetchAuthUrl, 383 getFileMeta, 384 getFileTypeFromHash, 385 getFilesAppStats, 386 getFilesMediaTypeStats, 387 getFilesStats, 388 getFilesUserStats, 389 getHashesByIds, 390 getImageSrcFromHash, 391 getOriginalUrl, 392 getPublicFileUrl, 393 getPublicThumbnailUrl, 394 getSizesFromHash, 395 getThumbnailUrl, 396 getThumbnailUrlById, 397 getUploadGetPutUrl, 398 getVideoInfo, 399 isAudioFile, 400 isImageFile, 401 isVideoFile, 402 listFiles, 403 makeFilePublic, 404 obtainStorageFilePutUrl, 405 restoreFileById, 406 startPartialStorageFileUpload, 407 updateFileMeta 408};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.