// Initializes the `files` service on path `/api/v1/files`
import { ServiceAddons } from '@feathersjs/feathers';
import BlobService from 'feathers-blob';
import multer from 'multer';
import { Application } from '../../declarations';
import logger from '../../logger';
import hooks from './files.hooks';
interface Data { }
interface ServiceOptions { }
// Add this service to the service type index
declare module '../../declarations' {
interface ServiceTypes {
'api/v1/files': ServiceAddons<any>;
}
}
const log = (msg) => logger.info('[File Service]: ' + msg)
const multipartMiddleware = multer();
export default function (app: Application) {
const storeOptions = app.get('blobStore');
let store;
if (storeOptions.type === 'local') {
log('Creating new local blob store:' + storeOptions.path)
const BlobStore = require('fs-blob-store');
store = BlobStore(storeOptions.path);
} else if (storeOptions.type === 's3') {
const AWS = require('aws-sdk');
const BlobStore = require('s3-blob-store')
log('Creating new s3 blob store:' + storeOptions.bucket)
AWS.config.update(storeOptions);
const s3 = new AWS.S3();
store = new BlobStore({
client: s3,
bucket: storeOptions.bucket,
});
}
const Files = new (BlobService as any)({
Model: store,
})
app.use('/api/v1/files',
// multer parses the file named 'uri'.
// Without extra params the data is
// temporarely kept in memory
multipartMiddleware.single('uri'),
// another middleware, this time to
// transfer the received file to feathers
function (req: any, res: any, next) {
req.feathers.file = req.file;
next();
},
Files,
);
// Get our initialized service so that we can register hooks
const service = app.service('api/v1/files');
service.hooks(hooks);
}
running tsc from the npm run compile command gives this error.
"compile": "rm -rf lib/ && tsc"
(First please check that this issue is not already solved as described
here)
Expected behavior
Feathers blob works with typescript
Actual behavior
node_modules/feathers-blob/types/index.d.ts:34:12 - error TS2709: Cannot use namespace 'AbstractBlobStore' as a type.
34 Model: AbstractBlobStore;
~~~~~~~~~~~~~~~~~
Found 1 error.
System configuration
Tell us about the applicable parts of your setup.
Module versions (especially the part that's not working):
Steps to reproduce
Using files.service.ts like so:
running tsc from the
npm run compile
command gives this error.(First please check that this issue is not already solved as described here)
Expected behavior
Feathers blob works with typescript
Actual behavior
System configuration
Tell us about the applicable parts of your setup.
Module versions (especially the part that's not working):
NodeJS version: 14.14.0 Operating System: MacOS Browser Version: Firefox