-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/release'
- Loading branch information
Showing
51 changed files
with
495 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
app/api/migrations/migrations/36-populate-mimetype-on-attachments/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import request from 'shared/JSONRequest'; | ||
import { attachmentsPath } from 'api/files/filesystem'; | ||
import mime from 'mime-types'; | ||
|
||
export default { | ||
delta: 36, | ||
|
||
name: 'populate-mimetype-to-attachment', | ||
|
||
description: 'Populates mimetype of an attachment from a url', | ||
|
||
async up(db) { | ||
process.stdout.write(`${this.name}...\r\n`); | ||
const cursor = await db.collection('files').find({}); | ||
|
||
// eslint-disable-next-line no-await-in-loop | ||
while (await cursor.hasNext()) { | ||
// eslint-disable-next-line no-await-in-loop | ||
const file = await cursor.next(); | ||
if (file.url && !file.mimetype) { | ||
// eslint-disable-next-line no-await-in-loop | ||
const response = await request.head(file.url); | ||
const mimetype = response.headers.get('content-type') || undefined; | ||
// eslint-disable-next-line no-await-in-loop | ||
await this.updateFile(db, file, mimetype); | ||
} else if (file.filename && file.type === 'attachment' && !file.mimetype) { | ||
const mimetype = mime.lookup(attachmentsPath(file.filename)) || undefined; | ||
// eslint-disable-next-line no-await-in-loop | ||
await this.updateFile(db, file, mimetype); | ||
} | ||
} | ||
}, | ||
async updateFile(db, file, mimetype) { | ||
if (mimetype) { | ||
await db.collection('files').updateOne({ _id: file._id }, { $set: { mimetype } }); | ||
} | ||
}, | ||
}; |
Oops, something went wrong.