⬇️ refactor: Assistant File Downloads (#2364)

* refactor(getFiledownload): explicit accept of `application/octet-stream`

* chore: test compose file

* chore: test compose file fix

* chore(files/download): add more logs

* Fix proxy_pass URLs in nginx.conf

* fix: proxy_pass URLs in nginx.conf to fix file downloads from URL

* chore: move test compose file to utils dir

* refactor(useFileDownload): simplify API request by passing `file_id` instead of `filepath`
This commit is contained in:
Danny Avila 2024-04-09 14:26:46 -04:00 committed by GitHub
parent cc71125fa1
commit cb64b84846
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 92 additions and 20 deletions

View file

@ -66,17 +66,16 @@ router.delete('/', async (req, res) => {
}
});
router.get('/download/:userId/:filepath', async (req, res) => {
router.get('/download/:userId/:file_id', async (req, res) => {
try {
const { userId, filepath } = req.params;
const { userId, file_id } = req.params;
logger.debug(`File download requested by user ${userId}: ${file_id}`);
if (userId !== req.user.id) {
logger.warn(`${errorPrefix} forbidden: ${file_id}`);
return res.status(403).send('Forbidden');
}
const parts = filepath.split('/');
const file_id = parts[2];
const [file] = await getFiles({ file_id });
const errorPrefix = `File download requested by user ${userId}`;
@ -114,8 +113,10 @@ router.get('/download/:userId/:filepath', async (req, res) => {
if (file.source === FileSources.openai) {
req.body = { model: file.model };
const { openai } = await initializeClient({ req, res });
logger.debug(`Downloading file ${file_id} from OpenAI`);
passThrough = await getDownloadStream(file_id, openai);
setHeaders();
logger.debug(`File ${file_id} downloaded from OpenAI`);
passThrough.body.pipe(res);
} else {
fileStream = getDownloadStream(file_id);