Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// --ipfs-api option
const IPFS = require('ipfs-http-client')
const addr = multiaddr(argv['ipfs-api'])
const nodeAddress = addr.nodeAddress()
ipfs = new IPFS(nodeAddress.address, nodeAddress.port)
} else {
const IPFS = require('ipfs')
ipfs = await IPFS.create({ start: false })
}
} catch (e) {
console.error(e)
throw new Error('Please use npm to install either `ipfs` or `ipfs-http-client`.')
}
// Register new MIME type for .ambient files
mime.extensions['text/ambients'] = ['ambient']
mime.types.ambient = 'text/ambients'
const file = fs.readFileSync(argv.input).toString().trim()
let result
switch (mime.lookup(argv.input)) {
case 'application/javascript':
result = await output(ipfs, file, argv); break
case 'text/ambients':
result = await output(ipfs, file, argv); break
default:
throw new Error('File type not recognized')
}
process.stdout.write(result + '\n')
process.exit(0)
function makeFileSuffix(media) {
var suffix = '';
var file = media.object;
var type = media.type;
// Strategy 1: use real filename if known
if (_.isString(file.file_name)) {
suffix = '/' + encodeURIComponentPlus(file.file_name);
}
// Strategy 2: use mime type to find an appropriate extension if it is known
var preferredExtensions = ['mp3', 'ogg', 'jpg'];
if (!suffix && _.isString(file.mime_type)) {
var extensions = mime.extensions[file.mime_type] || [];
var preferredMatches = _.intersection(extensions, preferredExtensions);
if (!_.isEmpty(preferredMatches)) {
suffix = '.' + _.head(preferredMatches);
} else if (!_.isEmpty(extensions)) {
suffix = '.' + _.head(extensions);
} else {
suffix = file.mime_type.replace(/^[^\/]*\//, '.');
}
}
// Strategy 3: guess appropriate extension based on Telegram media type
if (!suffix && type === 'sticker') {
suffix = '/sticker.webp';
if (svcConfig.decodeWebp) {
suffix += '.png';
}
const Bounce = require('@hapi/bounce');
const Mime = require('mime-types');
const StreamEach = require('stream-each');
const M3U8Parse = require('m3u8parse');
const debug = require('debug')('hls:recorder');
const HlsUploader = require('./hls-uploader');
const SegmentDecrypt = require('./segment-decrypt');
// Add custom extensions
Mime.extensions['audio/aac'] = ['aac'];
Mime.extensions['audio/ac3'] = ['ac3'];
Mime.extensions['video/iso.segment'] = ['m4s'];
const pathOrUriToURL = function (dirpathOrUri) {
if (!dirpathOrUri.endsWith('/')) {
dirpathOrUri = `${dirpathOrUri}/`;
}
const url = new URL(dirpathOrUri, 'r:/');
return url.protocol === 'r:' ? Url.pathToFileURL(dirpathOrUri) : url;
};
const HlsStreamRecorder = class {
constructor(reader, dst, options) {
const Path = require('path');
const Url = require('url');
const Bounce = require('@hapi/bounce');
const Mime = require('mime-types');
const StreamEach = require('stream-each');
const M3U8Parse = require('m3u8parse');
const debug = require('debug')('hls:recorder');
const HlsUploader = require('./hls-uploader');
const SegmentDecrypt = require('./segment-decrypt');
// Add custom extensions
Mime.extensions['audio/aac'] = ['aac'];
Mime.extensions['audio/ac3'] = ['ac3'];
Mime.extensions['video/iso.segment'] = ['m4s'];
const pathOrUriToURL = function (dirpathOrUri) {
if (!dirpathOrUri.endsWith('/')) {
dirpathOrUri = `${dirpathOrUri}/`;
}
const url = new URL(dirpathOrUri, 'r:/');
return url.protocol === 'r:' ? Url.pathToFileURL(dirpathOrUri) : url;
};
const HlsStreamRecorder = class {
export default function consoleLogServer (opts = {}) {
const mimeExtensions = _.flow(
_.values,
_.flatten,
_.without(['json'])
)(mime.extensions)
opts = _.defaults({
port: 3000,
hostname: 'localhost',
resultCode: 200,
resultBody: null,
resultHeader: [],
log: (...args) => {
console.log(...args)
},
defaultRoute: (req, res) => {
const negotiatedType = req.accepts(mimeExtensions)
const defaultHandler = () => opts.resultBody ? res.send(opts.resultBody) : res.end()
const headers = _.flow(
_.map((h) => h.split(':', 2)),
_.fromPairs
.map(type => mimetypes.extensions[type])
);
#!/usr/bin/env node
var path = require('path')
var getUrls = require('gh-md-urls')
var parseRepo = require('github-url-to-object')
var got = require('got')
var contentType = require('content-type')
var mimeExtensions = require('mime-types').extensions
var async = require('async')
var mkdirp = require('mkdirp')
var path = require('path')
var fs = require('fs')
var chalk = require('chalk')
var ghauth = require('ghauth')
var ASYNC_LIMIT = 20
var argv = require('minimist')(process.argv.slice(2), {
alias: {
extension: 'e',
rename: 'r'
},
boolean: ['verbose', 'auth']
})
_.forEach(ADDITIONAL_EXT_MIMETYPES, (mimeType, ext) => {
// don't override any entries
if(!_.isString(mimeTypes.types[ext])) {
mimeTypes[ext] = mimeType;
}
if(!mimeTypes.extensions[mimeType]) {
mimeTypes.extensions[mimeType] = [ ext ];
}
});
_.each(Object.keys(typesToRig), (type) => {
let ext = typesToRig[type];
mimeTypes.types[ext] = type;
mimeTypes.extensions[type] = _.clone([ext], true);
});
}
_.forEach(ADDITIONAL_EXT_MIMETYPES, (mimeType, ext) => {
// don't override any entries
if(!_.isString(mimeTypes.types[ext])) {
mimeTypes[ext] = mimeType;
}
if(!mimeTypes.extensions[mimeType]) {
mimeTypes.extensions[mimeType] = [ ext ];
}
});