Skip to content

Commit

Permalink
refactor(top): subir archivos a andesDrive
Browse files Browse the repository at this point in the history
  • Loading branch information
juuliotero authored and liquid36 committed Dec 28, 2020
1 parent 67254b7 commit 51d0753
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions modules/rup/routes/rupStore.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,28 @@
import { readFile, storeFile } from '../../../core/tm/controller/file-storage';
import * as express from 'express';
import { asyncHandler } from '@andes/api-tool';
import { AndesDrive } from '@andes/drive';
const router = express.Router();

const CollectionName = 'RupStore';

router.get('/store/:id', asyncHandler(async (req, res) => {
const fileData = await readFile(req.params.id, CollectionName);
res.contentType(fileData.file.contentType);
fileData.stream.pipe(res);
}));
router.get('/store/:id', async (req, res, next) => {
const fileDrive = await AndesDrive.find(req.params.id);
if (fileDrive) {
const stream1 = await AndesDrive.read(fileDrive);
res.contentType(fileDrive.mimetype);
stream1.pipe(res);
} else {
const data = await readFile(req.params.id, CollectionName);
res.contentType(data.file.contentType);
data.stream.on('data', (data2) => {
res.write(data2);
});
data.stream.on('end', () => {
res.end();
});
}
});

router.post('/store', asyncHandler(async (req, res) => {
const file = req.body.file;
Expand Down

0 comments on commit 51d0753

Please sign in to comment.