@stemy/backend 5.2.0 → 5.2.2
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/common-types.d.ts +10 -6
- package/esm2020/common-types.mjs +1 -1
- package/esm2020/public_api.mjs +3 -1
- package/esm2020/rest-controllers/assets.controller.mjs +17 -9
- package/esm2020/services/asset-resolver.mjs +1 -1
- package/esm2020/services/assets.mjs +2 -2
- package/esm2020/services/drivers/asset-local.driver.mjs +39 -0
- package/esm2020/services/lazy-assets.mjs +1 -1
- package/fesm2015/stemy-backend.mjs +58 -14
- package/fesm2015/stemy-backend.mjs.map +1 -1
- package/fesm2020/stemy-backend.mjs +53 -12
- package/fesm2020/stemy-backend.mjs.map +1 -1
- package/package.json +1 -1
- package/public_api.d.ts +3 -1
- package/rest-controllers/assets.controller.d.ts +6 -3
- package/services/asset-resolver.d.ts +2 -1
- package/services/assets.d.ts +2 -1
- package/services/drivers/asset-local.driver.d.ts +11 -0
- package/services/lazy-assets.d.ts +2 -1
|
@@ -8,7 +8,7 @@ import fontKit_ from 'fontkit';
|
|
|
8
8
|
import sharp_ from 'sharp';
|
|
9
9
|
import { ObjectId as ObjectId$1 } from 'bson';
|
|
10
10
|
import axios from 'axios';
|
|
11
|
-
import { mkdir, unlink, readFile as readFile$1, writeFile as writeFile$1, lstat, readdir, access, constants, lstatSync, readFileSync, existsSync } from 'fs';
|
|
11
|
+
import { mkdir, unlink, readFile as readFile$1, writeFile as writeFile$1, lstat, readdir, access, constants, lstatSync, readFileSync, existsSync, mkdirSync, createWriteStream, createReadStream } from 'fs';
|
|
12
12
|
import { gzip, gunzip } from 'zlib';
|
|
13
13
|
import { fileURLToPath } from 'url';
|
|
14
14
|
import { exec } from 'child_process';
|
|
@@ -16,7 +16,7 @@ import { createHash } from 'crypto';
|
|
|
16
16
|
import { Subscription, Observable, Subject, from, BehaviorSubject } from 'rxjs';
|
|
17
17
|
import { canReportError } from 'rxjs/internal/util/canReportError';
|
|
18
18
|
import { ObjectId } from 'mongodb';
|
|
19
|
-
import mongoose from 'mongoose';
|
|
19
|
+
import mongoose, { Types } from 'mongoose';
|
|
20
20
|
import { Readable, PassThrough } from 'stream';
|
|
21
21
|
import fileType from 'file-type/core';
|
|
22
22
|
import dotenv from 'dotenv';
|
|
@@ -38,6 +38,7 @@ import { CommandsAddon, AnsiCodes } from '@stemy/terminal-commands-addon';
|
|
|
38
38
|
import { compare } from 'bcrypt';
|
|
39
39
|
import moment from 'moment';
|
|
40
40
|
import { GridFSBucket } from 'mongodb/lib/gridfs';
|
|
41
|
+
import { writeFile as writeFile$2, rm } from 'fs/promises';
|
|
41
42
|
import { getModelForClass } from '@typegoose/typegoose';
|
|
42
43
|
import { getValue as getValue$1, setValue } from 'mongoose/lib/utils';
|
|
43
44
|
|
|
@@ -1092,7 +1093,7 @@ let Assets = class Assets {
|
|
|
1092
1093
|
this.connector = connector;
|
|
1093
1094
|
this.assetProcessor = assetProcessor;
|
|
1094
1095
|
this.driver = driver;
|
|
1095
|
-
this.collection = connector.database?.collection(
|
|
1096
|
+
this.collection = connector.database?.collection("assets.metadata");
|
|
1096
1097
|
}
|
|
1097
1098
|
async write(stream, contentType = null, metadata = null) {
|
|
1098
1099
|
const uploadStream = copyStream(stream);
|
|
@@ -2852,10 +2853,7 @@ let AssetsController = class AssetsController {
|
|
|
2852
2853
|
const asset = await this.getAssetByName("Image", name, res);
|
|
2853
2854
|
return asset.downloadImage(params);
|
|
2854
2855
|
}
|
|
2855
|
-
setAssetHeaders(
|
|
2856
|
-
if (asset.metadata?.classified) {
|
|
2857
|
-
throw new HttpError(403, `${type} is classified, and can be only downloaded from a custom url.`);
|
|
2858
|
-
}
|
|
2856
|
+
setAssetHeaders(asset, res) {
|
|
2859
2857
|
const ext = asset.metadata?.extension;
|
|
2860
2858
|
if (ext) {
|
|
2861
2859
|
res.header("content-disposition", `inline; filename=${asset.filename}.${ext}`);
|
|
@@ -2865,19 +2863,30 @@ let AssetsController = class AssetsController {
|
|
|
2865
2863
|
}
|
|
2866
2864
|
}
|
|
2867
2865
|
async getAsset(type, id, lazy, res) {
|
|
2868
|
-
|
|
2866
|
+
let asset = await this.assetResolver.resolve(id, lazy);
|
|
2869
2867
|
if (!asset) {
|
|
2870
2868
|
throw new HttpError(404, `${type} with id: '${id}' not found.`);
|
|
2871
2869
|
}
|
|
2872
|
-
this.
|
|
2870
|
+
asset = await this.resolveFinalAsset(type, asset);
|
|
2871
|
+
this.setAssetHeaders(asset, res);
|
|
2873
2872
|
return asset;
|
|
2874
2873
|
}
|
|
2875
2874
|
async getAssetByName(type, filename, res) {
|
|
2876
|
-
|
|
2875
|
+
let asset = await this.assets.find({ filename });
|
|
2877
2876
|
if (!asset) {
|
|
2878
2877
|
throw new HttpError(404, `${type} with filename: '${filename}' not found.`);
|
|
2879
2878
|
}
|
|
2880
|
-
this.
|
|
2879
|
+
asset = await this.resolveFinalAsset(type, asset);
|
|
2880
|
+
this.setAssetHeaders(asset, res);
|
|
2881
|
+
return asset;
|
|
2882
|
+
}
|
|
2883
|
+
async resolveFinalAsset(type, asset) {
|
|
2884
|
+
if (asset.metadata?.classified) {
|
|
2885
|
+
throw new HttpError(403, `${type} is classified, and can be only downloaded from a custom url.`);
|
|
2886
|
+
}
|
|
2887
|
+
if (type == 'Image' && asset.metadata.preview) {
|
|
2888
|
+
return this.resolveFinalAsset(type, await this.assetResolver.resolve(asset.metadata.preview));
|
|
2889
|
+
}
|
|
2881
2890
|
return asset;
|
|
2882
2891
|
}
|
|
2883
2892
|
};
|
|
@@ -3880,6 +3889,38 @@ AssetGridDriver = __decorate([
|
|
|
3880
3889
|
__metadata("design:paramtypes", [MongoConnector])
|
|
3881
3890
|
], AssetGridDriver);
|
|
3882
3891
|
|
|
3892
|
+
let AssetLocalDriver = class AssetLocalDriver {
|
|
3893
|
+
constructor(dir) {
|
|
3894
|
+
this.dir = dir;
|
|
3895
|
+
this.metaCollection = "assets.local";
|
|
3896
|
+
}
|
|
3897
|
+
openUploadStream(filename, opts) {
|
|
3898
|
+
const id = new Types.ObjectId();
|
|
3899
|
+
const dir = `${this.dir}/${id.toHexString()}`;
|
|
3900
|
+
mkdirSync(dir, { recursive: true });
|
|
3901
|
+
const stream = createWriteStream(`${dir}/file.bin`);
|
|
3902
|
+
stream.id = id;
|
|
3903
|
+
stream.done = false;
|
|
3904
|
+
stream.on('finish', () => {
|
|
3905
|
+
writeFile$2(`${dir}/filename.txt`, filename);
|
|
3906
|
+
writeFile$2(`${dir}/metadata.json`, JSON.stringify(opts?.metadata || {}));
|
|
3907
|
+
stream.done = true;
|
|
3908
|
+
});
|
|
3909
|
+
return stream;
|
|
3910
|
+
}
|
|
3911
|
+
openDownloadStream(id) {
|
|
3912
|
+
return createReadStream(`${this.dir}/${id.toHexString()}/file.bin`, { autoClose: true, emitClose: true });
|
|
3913
|
+
}
|
|
3914
|
+
delete(id) {
|
|
3915
|
+
return rm(`${this.dir}/${id.toHexString()}`, { recursive: true, force: true });
|
|
3916
|
+
}
|
|
3917
|
+
};
|
|
3918
|
+
AssetLocalDriver = __decorate([
|
|
3919
|
+
injectable(),
|
|
3920
|
+
__param(0, inject(LOCAL_DIR)),
|
|
3921
|
+
__metadata("design:paramtypes", [String])
|
|
3922
|
+
], AssetLocalDriver);
|
|
3923
|
+
|
|
3883
3924
|
class BaseDoc {
|
|
3884
3925
|
/**
|
|
3885
3926
|
* Casts this to DocumentType<this> to allow using document methods in get/set-s
|
|
@@ -4485,5 +4526,5 @@ async function setupBackend(config, providers, parent) {
|
|
|
4485
4526
|
* Generated bundle index. Do not edit.
|
|
4486
4527
|
*/
|
|
4487
4528
|
|
|
4488
|
-
export { AssetImageParams, AssetProcessor, AssetResolver, Assets, AuthController, BackendProvider, BaseDoc, Cache, CacheProcessor, Configuration, ConsoleColor, DI_CONTAINER, DocumentArray, EXPRESS, EndpointProvider, ErrorHandlerMiddleware, FIXTURE, Fixtures, Gallery, GalleryCache, GalleryController, HTTP_SERVER, IdGenerator, IsDocumented, IsFile, IsObjectId, JOB, JobManager, JsonResponse, LanguageMiddleware, LazyAssetGenerator, LazyAssets, Logger, MailSender, MemoryCache, MongoConnector, OPENAPI_VALIDATION, OpenApi, PARAMETER, Parameter, PrimitiveArray, Progresses, ResolveEntity, ResponseType, SOCKET_CONTROLLERS, SOCKET_SERVER, TERMINAL_COMMAND, TemplateRenderer, TerminalManager, TokenGenerator, TranslationProvider, Translator, Type, UserManager, assign, broadcast, bufferToStream, camelCaseToDash, colorize, convertValue, copy, copyStream, createIdString, createServices, createTransformer, deleteFile, deleteFromBucket, fileTypeFromBuffer, fileTypeFromStream, filter, firstItem, flatten, getConstructorName, getDirName, getExtension, getFileName, getFunctionParams, getType, getValue, groupBy, gunzipPromised, gzipPromised, hydratePopulated, idToString, injectServices, isArray, isBoolean, isBuffer, isConstructor, isDate, isDefined, isFunction, isInterface, isNullOrUndefined, isObject, isObjectId, isPrimitive, isString, isType, jsonHighlight, lastItem, lcFirst, letsLookupStage, lookupStages, matchField, matchFieldStages, matchStage, md5, mkdirRecursive, multiSubscription, observableFromFunction, padLeft, padRight, paginate, paginateAggregations, prepareUrl, prepareUrlEmpty, prepareUrlSlash, projectStage, promiseTimeout, rand, random, readAndDeleteFile, readFile, regexEscape, regroup, replaceSpecialChars, resolveUser, runCommand, service, setupBackend, streamToBuffer, toImage, ucFirst, uniqueItems, unwindStage, valueToPromise, wrapError, writeFile };
|
|
4529
|
+
export { AssetGridDriver, AssetImageParams, AssetLocalDriver, AssetProcessor, AssetResolver, Assets, AuthController, BackendProvider, BaseDoc, Cache, CacheProcessor, Configuration, ConsoleColor, DI_CONTAINER, DocumentArray, EXPRESS, EndpointProvider, ErrorHandlerMiddleware, FIXTURE, Fixtures, Gallery, GalleryCache, GalleryController, HTTP_SERVER, IdGenerator, IsDocumented, IsFile, IsObjectId, JOB, JobManager, JsonResponse, LanguageMiddleware, LazyAssetGenerator, LazyAssets, Logger, MailSender, MemoryCache, MongoConnector, OPENAPI_VALIDATION, OpenApi, PARAMETER, Parameter, PrimitiveArray, Progresses, ResolveEntity, ResponseType, SOCKET_CONTROLLERS, SOCKET_SERVER, TERMINAL_COMMAND, TemplateRenderer, TerminalManager, TokenGenerator, TranslationProvider, Translator, Type, UserManager, assign, broadcast, bufferToStream, camelCaseToDash, colorize, convertValue, copy, copyStream, createIdString, createServices, createTransformer, deleteFile, deleteFromBucket, fileTypeFromBuffer, fileTypeFromStream, filter, firstItem, flatten, getConstructorName, getDirName, getExtension, getFileName, getFunctionParams, getType, getValue, groupBy, gunzipPromised, gzipPromised, hydratePopulated, idToString, injectServices, isArray, isBoolean, isBuffer, isConstructor, isDate, isDefined, isFunction, isInterface, isNullOrUndefined, isObject, isObjectId, isPrimitive, isString, isType, jsonHighlight, lastItem, lcFirst, letsLookupStage, lookupStages, matchField, matchFieldStages, matchStage, md5, mkdirRecursive, multiSubscription, observableFromFunction, padLeft, padRight, paginate, paginateAggregations, prepareUrl, prepareUrlEmpty, prepareUrlSlash, projectStage, promiseTimeout, rand, random, readAndDeleteFile, readFile, regexEscape, regroup, replaceSpecialChars, resolveUser, runCommand, service, setupBackend, streamToBuffer, toImage, ucFirst, uniqueItems, unwindStage, valueToPromise, wrapError, writeFile };
|
|
4489
4530
|
//# sourceMappingURL=stemy-backend.mjs.map
|