diff --git a/controllers/frontend/account.js b/controllers/frontend/account.js index f490e94d..68222b93 100644 --- a/controllers/frontend/account.js +++ b/controllers/frontend/account.js @@ -884,6 +884,7 @@ exports.livestreaming = async(req, res) => var networkInterfaces = os.networkInterfaces( ); + // TODO: probably not the best way to get the ip address const ipAddress = networkInterfaces.lo0 && networkInterfaces.lo0[0].address || networkInterfaces.eth0 && networkInterfaces.eth0[0].address; const address = process.env.LIVESTREAM_RTMP_DOMAIN || ipAddress; @@ -925,16 +926,15 @@ exports.livestreaming = async(req, res) => */ exports.getImporter = (req, res) => { - const recaptchaPublicKey = process.env.RECAPTCHA_SITEKEY; - - const captchaOn = process.env.RECAPTCHA_ON == 'true'; - if(!req.user){ return res.redirect('/login'); } + + if(req.user.channelUrl !== 'anthony'){ + return res.redirect('/login'); + } + res.render('account/importer', { - title: 'Create Account', - recaptchaPublicKey, - captchaOn + title: 'Importer', }); }; diff --git a/lib/uploading/importer.js b/lib/uploading/importer.js index d90578b0..28efaecd 100644 --- a/lib/uploading/importer.js +++ b/lib/uploading/importer.js @@ -1,5 +1,7 @@ const Promise = require('bluebird'); const fs = Promise.promisifyAll(require('fs')); +const FileType = require('file-type'); +const webp = require('webp-converter'); const youtubedl = require('youtube-dl'); @@ -8,6 +10,7 @@ const Upload = require('../../models/index').Upload; const User = require('../../models/index').User; + const requestModule = require('request'); const request = Promise.promisifyAll(requestModule); const _ = require('lodash'); @@ -36,6 +39,17 @@ async function downloadAndSaveThumbnails(thumbnailUrl, uniqueTag, channelUrl, ex await fs.writeFileAsync(thumbnailDestination, thumbnail.body, 'binary'); + // TODO: test : is this webp? + + // if so, have to convert that file to png via that libary + // const result = webp.dwebp(originalFile, convertedFile, "-o"); + + // then return the path of that file as this function + + // also pass that extension + + // return the extension + console.log(`THUMBNAILS SAVED LOCALLY`); console.log(uniqueTag) diff --git a/lib/uploading/tester.js b/lib/uploading/tester.js new file mode 100644 index 00000000..d0b37af4 --- /dev/null +++ b/lib/uploading/tester.js @@ -0,0 +1,53 @@ +const FileType = require('file-type'); +const webp = require('webp-converter'); + + +(async () => { + const fileTypeData = await FileType.fromFile('hq1.jpg'); + + const extension = fileTypeData.ext; + + const mime = fileTypeData.mime; + + if(extension == 'webp'){ + console.log('webp fo sho') + } + + console.log(extension, mime); + + + + + + + + // console.log(fileTypeData.ext); + //=> {ext: 'png', mime: 'image/png'} +}); + + +async function main(){ + const fileTypeData = await FileType.fromFile('hq2.png'); + + console.log(fileTypeData) +} + +// main(); + + +function convertFile(originalFile, convertedFile){ + const result = webp.dwebp(originalFile, convertedFile, "-o"); + + result.then((response) => { + console.log(response); + }); +} + +const originalFile = 'hq1.jpg'; +const convertedFile = 'hq2.png'; + +module.exports = convertFile; + +// make sure convertedFile is .png +// convertFile(originalFile, convertedFile); + diff --git a/package-lock.json b/package-lock.json index 86dc24cc..e25d570c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -18,6 +18,11 @@ "resolved": "https://registry.npmjs.org/@nodelib/fs.stat/-/fs.stat-1.1.3.tgz", "integrity": "sha1-K1o6s/kYzKSKjHVMCBaOPwPrphs=" }, + "@tokenizer/token": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/@tokenizer/token/-/token-0.1.1.tgz", + "integrity": "sha512-XO6INPbZCxdprl+9qa/AAbFFOMzzwqYxpjPgLICrMD6C2FCw6qfJOPcBk6JqqPLSaZ/Qx87qn4rpPmPMwaAK6w==" + }, "@types/babel-types": { "version": "7.0.7", "resolved": "https://registry.npmjs.org/@types/babel-types/-/babel-types-7.0.7.tgz", @@ -58,6 +63,11 @@ "@types/node": "*" } }, + "@types/debug": { + "version": "4.1.5", + "resolved": "https://registry.npmjs.org/@types/debug/-/debug-4.1.5.tgz", + "integrity": "sha512-Q1y515GcOdTHgagaVFhHnIFQ38ygs/kmxdNpvpou+raI9UO3YZcHDngBSYKQklcKlvA7iuQlmIKbzvmxcOE9CQ==" + }, "@types/events": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/@types/events/-/events-3.0.0.tgz", @@ -3335,6 +3345,17 @@ "object-assign": "^4.0.1" } }, + "file-type": { + "version": "15.0.1", + "resolved": "https://registry.npmjs.org/file-type/-/file-type-15.0.1.tgz", + "integrity": "sha512-0LieQlSA3bWUdErNrxzxfI4rhsvNAVPBO06R8pTc1hp9SE6nhqlVyvhcaXoMmtXkBTPnQenbMPLW9X76hH76oQ==", + "requires": { + "readable-web-to-node-stream": "^2.0.0", + "strtok3": "^6.0.3", + "token-types": "^2.0.0", + "typedarray-to-buffer": "^3.1.5" + } + }, "file-uri-to-path": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz", @@ -7598,6 +7619,11 @@ "semver": "^5.0.3" } }, + "peek-readable": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/peek-readable/-/peek-readable-3.1.0.tgz", + "integrity": "sha512-KGuODSTV6hcgdZvDrIDBUkN0utcAVj1LL7FfGbM0viKTtCHmtZcuEJ+lGqsp0fTFkGqesdtemV2yUSMeyy3ddA==" + }, "pend": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/pend/-/pend-1.2.0.tgz", @@ -8143,6 +8169,11 @@ "util-deprecate": "^1.0.1" } }, + "readable-web-to-node-stream": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/readable-web-to-node-stream/-/readable-web-to-node-stream-2.0.0.tgz", + "integrity": "sha512-+oZJurc4hXpaaqsN68GoZGQAQIA3qr09Or4fqEsargABnbe5Aau8hFn6ISVleT3cpY/0n/8drn7huyyEvTbghA==" + }, "readdirp": { "version": "2.2.1", "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-2.2.1.tgz", @@ -9558,6 +9589,16 @@ } } }, + "strtok3": { + "version": "6.0.4", + "resolved": "https://registry.npmjs.org/strtok3/-/strtok3-6.0.4.tgz", + "integrity": "sha512-rqWMKwsbN9APU47bQTMEYTPcwdpKDtmf1jVhHzNW2cL1WqAxaM9iBb9t5P2fj+RV2YsErUWgQzHD5JwV0uCTEQ==", + "requires": { + "@tokenizer/token": "^0.1.1", + "@types/debug": "^4.1.5", + "peek-readable": "^3.1.0" + } + }, "superagent": { "version": "3.8.3", "resolved": "https://registry.npmjs.org/superagent/-/superagent-3.8.3.tgz", @@ -9865,6 +9906,15 @@ "resolved": "https://registry.npmjs.org/token-stream/-/token-stream-0.0.1.tgz", "integrity": "sha1-zu78cXp2xDFvEm0LnbqlXX598Bo=" }, + "token-types": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/token-types/-/token-types-2.0.0.tgz", + "integrity": "sha512-WWvu8sGK8/ZmGusekZJJ5NM6rRVTTDO7/bahz4NGiSDb/XsmdYBn6a1N/bymUHuWYTWeuLUg98wUzvE4jPdCZw==", + "requires": { + "@tokenizer/token": "^0.1.0", + "ieee754": "^1.1.13" + } + }, "touch": { "version": "0.0.3", "resolved": "https://registry.npmjs.org/touch/-/touch-0.0.3.tgz", @@ -10027,6 +10077,14 @@ "resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz", "integrity": "sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=" }, + "typedarray-to-buffer": { + "version": "3.1.5", + "resolved": "https://registry.npmjs.org/typedarray-to-buffer/-/typedarray-to-buffer-3.1.5.tgz", + "integrity": "sha512-zdu8XMNEDepKKR+XYOXAVPtWui0ly0NtohUscw+UmaHiAWT8hrV1rr//H6V+0DvJ3OQ19S979M0laLfX8rm82Q==", + "requires": { + "is-typedarray": "^1.0.0" + } + }, "uglify-js": { "version": "3.7.6", "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.7.6.tgz", @@ -10359,6 +10417,11 @@ "snekfetch": "^3.6.4" } }, + "webp-converter": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/webp-converter/-/webp-converter-2.3.0.tgz", + "integrity": "sha512-FJJm9wYEV2sBhcqdQGgOowaCPdyf1yBAbgJVhI5m62f1lEyiAPgYxLHXmKQs/68DhL7dOyo59sr/LdW1UUBNBg==" + }, "which": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/which/-/which-1.3.1.tgz", diff --git a/package.json b/package.json index 04352466..befe6a42 100644 --- a/package.json +++ b/package.json @@ -59,6 +59,7 @@ "express-useragent": "^1.0.12", "express-validator": "^3.1.2", "fbgraph": "^1.4.4", + "file-type": "^15.0.1", "fluent-ffmpeg": "^2.1.2", "forever": "^2.0.0", "formidable": "^1.2.1", @@ -116,6 +117,7 @@ "twit": "^2.2.11", "validator": "^7.0.0", "webhook-discord": "^3.5.1", + "webp-converter": "^2.3.0", "winston": "^3.2.1", "ws": "^3.3.3", "youtube-dl": "github:mayeaux/workingyoutubedl",