1- "use strict" ;
21var __extends = ( this && this . __extends ) || ( function ( ) {
32 var extendStatics = function ( d , b ) {
43 extendStatics = Object . setPrototypeOf ||
@@ -24,8 +23,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
2423 } ) ;
2524} ;
2625var __generator = ( this && this . __generator ) || function ( thisArg , body ) {
27- var _ = { label : 0 , sent : function ( ) { if ( t [ 0 ] & 1 ) throw t [ 1 ] ; return t [ 1 ] ; } , trys : [ ] , ops : [ ] } , f , y , t , g ;
28- return g = { next : verb ( 0 ) , "throw" : verb ( 1 ) , "return" : verb ( 2 ) } , typeof Symbol === "function" && ( g [ Symbol . iterator ] = function ( ) { return this ; } ) , g ;
26+ var _ = { label : 0 , sent : function ( ) { if ( t [ 0 ] & 1 ) throw t [ 1 ] ; return t [ 1 ] ; } , trys : [ ] , ops : [ ] } , f , y , t , g = Object . create ( ( typeof Iterator === "function" ? Iterator : Object ) . prototype ) ;
27+ return g . next = verb ( 0 ) , g [ "throw" ] = verb ( 1 ) , g [ "return" ] = verb ( 2 ) , typeof Symbol === "function" && ( g [ Symbol . iterator ] = function ( ) { return this ; } ) , g ;
2928 function verb ( n ) { return function ( v ) { return step ( [ n , v ] ) ; } ; }
3029 function step ( op ) {
3130 if ( f ) throw new TypeError ( "Generator is already executing." ) ;
@@ -51,27 +50,25 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
5150 }
5251} ;
5352var _a ;
54- Object . defineProperty ( exports , "__esModule" , { value : true } ) ;
55- exports . controller = exports . createThumbnailStreamIfNeeded = exports . TooLargeError = exports . TOO_LARGE_FLAG = exports . FileSchema = void 0 ;
56- var mongoose = require ( "mongoose" ) ;
57- var path = require ( "path" ) ;
58- var busboy = require ( "busboy" ) ;
59- var ims = require ( "imagemagick-stream" ) ;
53+ import mongoose from "mongoose" ;
54+ import path from "path" ;
55+ import busboy from "busboy" ;
56+ import ims from "imagemagick-stream" ;
6057// the numeric values are written to the document property that stores the reference to the file (which
6158// will be of type FileSchemaObj, using schema FileSchema - see below).
6259var StoreInMongoDB = 1 ;
63- exports . FileSchema = {
60+ export var FileSchema = {
6461 filename : String ,
6562 size : Number ,
66- location : Number ,
63+ location : Number , // valueof StoredFileLocation
6764 thumbnailId : {
6865 type : mongoose . Schema . Types . ObjectId ,
6966 form : {
7067 hidden : true , // needed to prevent fng from complaining about "No supported select lookup type..."
7168 } ,
7269 } ,
7370} ;
74- exports . TOO_LARGE_FLAG = "__tooLarge" ;
71+ export var TOO_LARGE_FLAG = "__tooLarge" ;
7572var TooLargeError = /** @class */ ( function ( _super ) {
7673 __extends ( TooLargeError , _super ) ;
7774 function TooLargeError ( ) {
@@ -82,8 +79,8 @@ var TooLargeError = /** @class */ (function (_super) {
8279 }
8380 return TooLargeError ;
8481} ( Error ) ) ;
85- exports . TooLargeError = TooLargeError ;
86- _a = exports . TOO_LARGE_FLAG ;
82+ export { TooLargeError } ;
83+ _a = TOO_LARGE_FLAG ;
8784function storeOneFileInMongoDB ( gridFSBucket , file , options , callback ) {
8885 var internalOptions = { } ;
8986 if ( options . metadata ) {
@@ -102,7 +99,7 @@ function storeOneFileInMongoDB(gridFSBucket, file, options, callback) {
10299 } ) ;
103100 file . pipe ( stream ) ;
104101}
105- function createThumbnailStreamIfNeeded ( opts , filename ) {
102+ export function createThumbnailStreamIfNeeded ( opts , filename ) {
106103 if ( ! opts . required ) {
107104 return ;
108105 }
@@ -133,7 +130,6 @@ function createThumbnailStreamIfNeeded(opts, filename) {
133130 // unsharp can improve the image quality after the resize. See https://legacy.imagemagick.org/Usage/thumbnails/#height.
134131 return ims ( ) . thumbnail ( size ) . autoOrient ( ) . op ( "unsharp" , "0x.5" ) . inputFormat ( type ) . outputFormat ( type ) ;
135132}
136- exports . createThumbnailStreamIfNeeded = createThumbnailStreamIfNeeded ;
137133function storeInMongoDB ( fng , resource , file , filename , schemaThumbnailOpts ) {
138134 var mongo = fng . mongoose . mongo ;
139135 var bucketName = resource . model . collection . name ;
@@ -176,7 +172,7 @@ function storeInMongoDB(fng, resource, file, filename, schemaThumbnailOpts) {
176172 } ) ;
177173 } ) ;
178174}
179- function controller ( fng , processArgs , options ) {
175+ export function controller ( fng , processArgs , options ) {
180176 var modifiedFngOpts = Object . assign ( { } , fng . options ) ;
181177 if ( options . inhibitAuthentication ) {
182178 delete modifiedFngOpts . authentication ;
@@ -228,7 +224,7 @@ function controller(fng, processArgs, options) {
228224 // handler, below, because otherwise the error will leak out to the "next" handler and get reported to Sentry
229225 . catch ( function ( e ) {
230226 // can't use instanceof here (think the compiler options need to be more up-to-date to allow that)
231- if ( exports . TOO_LARGE_FLAG in e ) {
227+ if ( TOO_LARGE_FLAG in e ) {
232228 var units = "byte" ;
233229 var value = storageLimits . maxFileSize ;
234230 if ( value % 1024 === 0 ) {
@@ -350,6 +346,10 @@ function controller(fng, processArgs, options) {
350346 ] ) ) ;
351347 // the route used when deleting a file (when clicking on the trashcan icon that is provided alongside the thumbnail)
352348 fng . app . delete . apply ( fng . app , processArgs ( modifiedFngOpts , [
349+ // if you think you want to change this route (in particular, changing the name of the :id param),
350+ // ensure that the host app does not (through the modifiedFngArgs) inject some additional handlers
351+ // (perhaps related to permissions) which expect certain params to exist.
352+ // Plait developer note: :id is assumed to exist in the async function check() of permissions.ts
353353 "file/:model/:location/:id" ,
354354 function ( req , res ) {
355355 return __awaiter ( this , void 0 , void 0 , function ( ) {
@@ -419,4 +419,4 @@ function controller(fng, processArgs, options) {
419419 // but in our case, we have nothing, so we can simply...
420420 return retVal ;
421421}
422- exports . controller = controller ;
422+ export default { controller : controller , FileSchema : FileSchema } ;
0 commit comments