2020-10-13 15:33:56 +00:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
|
|
|
const copyright =
|
2022-01-20 18:27:56 +00:00
|
|
|
`// This file Copyright © 2021-${new Date().getFullYear()} Mnemosyne LLC.
|
2022-08-08 18:05:39 +00:00
|
|
|
// It may be used under GPLv2 (SPDX: GPL-2.0-only), GPLv3 (SPDX: GPL-3.0-only),
|
2022-01-20 18:27:56 +00:00
|
|
|
// or any future license endorsed by Mnemosyne LLC.
|
|
|
|
// License text can be found in the licenses/ folder.`;
|
2020-10-13 15:33:56 +00:00
|
|
|
|
|
|
|
const fs = require('fs');
|
|
|
|
const https = require('https');
|
|
|
|
|
|
|
|
// https://github.com/jshttp/mime-db
|
|
|
|
// > If you're crazy enough to use this in the browser, you can just grab
|
|
|
|
// > the JSON file using jsDelivr. It is recommended to replace master with
|
|
|
|
// > a release tag as the JSON format may change in the future.
|
|
|
|
//
|
|
|
|
// This script keeps it at `master` to pick up any fixes that may have landed.
|
|
|
|
// If the format changes, we'll just update this script.
|
|
|
|
const url = 'https://cdn.jsdelivr.net/gh/jshttp/mime-db@master/db.json';
|
|
|
|
|
|
|
|
https.get(url, (res) => {
|
|
|
|
res.setEncoding('utf8');
|
|
|
|
const chunks = [];
|
|
|
|
res.on('data', (chunk) => chunks.push(chunk));
|
|
|
|
res.on('end', () => {
|
|
|
|
try {
|
|
|
|
const suffixes = [];
|
|
|
|
const mime_types = JSON.parse(chunks.join(''));
|
|
|
|
for (const [mime_type, info] of Object.entries(mime_types)) {
|
|
|
|
for (const suffix of info?.extensions || []) {
|
|
|
|
suffixes.push([ suffix, mime_type ]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const mime_type_lines = suffixes
|
2021-10-01 22:55:19 +00:00
|
|
|
.map(([suffix, mime_type]) => ` { "${suffix}", "${mime_type}" }`)
|
2020-10-13 15:33:56 +00:00
|
|
|
.sort()
|
|
|
|
.join(',\n');
|
|
|
|
fs.writeFileSync('mime-types.h', `${copyright}
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2021-10-01 22:55:19 +00:00
|
|
|
#include <array>
|
|
|
|
#include <string_view>
|
2020-10-13 15:33:56 +00:00
|
|
|
|
|
|
|
struct mime_type_suffix
|
|
|
|
{
|
2021-10-01 22:55:19 +00:00
|
|
|
std::string_view suffix;
|
|
|
|
std::string_view mime_type;
|
2020-10-13 15:33:56 +00:00
|
|
|
};
|
|
|
|
|
2021-10-01 22:55:19 +00:00
|
|
|
inline auto constexpr mime_type_suffixes = std::array<mime_type_suffix, ${suffixes.length}>
|
|
|
|
{{
|
|
|
|
${mime_type_lines}
|
|
|
|
}};
|
|
|
|
|
2020-10-13 15:33:56 +00:00
|
|
|
`);
|
|
|
|
} catch (e) {
|
|
|
|
console.error(e.message);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2021-10-01 22:55:19 +00:00
|
|
|
|