Skip to content

Commit

Permalink
Merge branch 'dodoc2-dev' into dodoc2-raspberry-dev2
Browse files Browse the repository at this point in the history
  • Loading branch information
louis-ev committed Sep 23, 2020
2 parents cfb4aca + 4cf1cb4 commit 56d440d
Show file tree
Hide file tree
Showing 168 changed files with 34,784 additions and 9,945 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,4 @@ Network Trash Folder
Temporary Items
.apdisk

changelog.csv
28 changes: 0 additions & 28 deletions .jshintrc

This file was deleted.

4 changes: 4 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"trailingComma": "es5",
"tabWidth": 2
}
16 changes: 0 additions & 16 deletions .vscode/launch.json

This file was deleted.

Binary file added build/icon.icns
Binary file not shown.
Binary file added build/icons/512x512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
85 changes: 49 additions & 36 deletions core/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ ffmpeg.setFfmpegPath(
path.join(global.appRoot, "ffmpeg-4.1.3-armhf-static", "ffmpeg")
);

module.exports = (function() {
module.exports = (function () {
const API = {
getFolderPath: (slugFolderName = "") => getFolderPath(slugFolderName),
findFirstFilenameNotTaken: (thisPath, fileName) =>
Expand All @@ -25,24 +25,25 @@ module.exports = (function() {
getCurrentDate(format),
convertDate: (date, format = global.settings.metaDateFormat) =>
convertDate(date, format),
parseUTCDate: date => parseUTCDate(date),
parseUTCDate: (date) => parseUTCDate(date),
parseDate: (date, format = global.settings.metaDateFormat) =>
parseDate(date, format),
storeData: (mpath, d, e) => storeData(mpath, d, e),
parseData: d => parseData(d),
parseData: (d) => parseData(d),
eventAndContent: (sendEvent, objectJson) =>
eventAndContent(sendEvent, objectJson),
sendEventWithContent: (sendEvent, objectContent, io, socket) =>
sendEventWithContent(sendEvent, objectContent, io, socket),
getNetworkInfos: () => getNetworkInfos(),
slug: term => slug(term),
removePasswordFromFoldersMeta: (d) => removePasswordFromFoldersMeta(d),
slug: (term) => slug(term),
clip: (value, min, max) => clip(value, min, max),
decodeBase64Image: dataString => decodeBase64Image(dataString),
decodeBase64Image: (dataString) => decodeBase64Image(dataString),
writeAudioToDisk: (slugFolderName, mediaName, dataURL) =>
writeAudioToDisk(slugFolderName, mediaName, dataURL),
writeVideoToDisk: (slugFolderName, mediaName, dataURL) =>
writeVideoToDisk(slugFolderName, mediaName, dataURL),
makeStopmotionFromImageSequence: d => makeStopmotionFromImageSequence(d)
makeStopmotionFromImageSequence: (d) => makeStopmotionFromImageSequence(d),
};

function _getUserPath() {
Expand Down Expand Up @@ -75,7 +76,7 @@ module.exports = (function() {

// check whether media (such as 'hello-world.mp4') already exists in the folder
function findFirstFilenameNotTaken(thisPath, fileName) {
return new Promise(function(resolve, reject) {
return new Promise(function (resolve, reject) {
// let's find the extension if it exists
var fileExtension = new RegExp(
global.settings.regexpGetFileExtension,
Expand Down Expand Up @@ -128,13 +129,13 @@ module.exports = (function() {
}

function storeData(mpath, d, e) {
return new Promise(function(resolve, reject) {
return new Promise(function (resolve, reject) {
dev.logfunction(`COMMON — storeData at path ${mpath}`);
// dev.logfunction(`with content ${d}`);
if (typeof d === "object") {
d = parsedown.textify(d);
}
writeFileAtomic(mpath, d, err => {
writeFileAtomic(mpath, d, (err) => {
if (err) {
reject(err);
}
Expand All @@ -146,7 +147,7 @@ module.exports = (function() {
function eventAndContent(sendEvent, objectJson) {
var eventContentJSON = {
socketevent: sendEvent,
content: objectJson
content: objectJson,
};
return eventContentJSON;
}
Expand Down Expand Up @@ -193,11 +194,11 @@ module.exports = (function() {

// from http://stackoverflow.com/a/8440736
function getLocalIP() {
return new Promise(function(resolve, reject) {
return new Promise(function (resolve, reject) {
const ifaces = os.networkInterfaces();
let ip_adresses = {};
Object.keys(ifaces).forEach(function(ifname) {
ifaces[ifname].forEach(function(iface) {
ifaces[ifname].forEach(function (iface) {
if ("IPv4" === iface.family && iface.internal === false) {
ip_adresses[ifname] = iface.address;
}
Expand All @@ -208,16 +209,28 @@ module.exports = (function() {
}

function getNetworkInfos() {
return new Promise(function(resolve, reject) {
getLocalIP().then(ip_adresses => {
return new Promise(function (resolve, reject) {
getLocalIP().then((ip_adresses) => {
resolve({
ip: Object.values(ip_adresses),
port: global.appInfos.port
port: global.appInfos.port,
});
});
});
}

function removePasswordFromFoldersMeta(foldersData) {
Object.keys(foldersData).map((s) => {
if (
foldersData[s].hasOwnProperty("password") &&
foldersData[s].password !== ""
) {
foldersData[s].password = "has_pass";
}
});
return foldersData;
}

function slug(term) {
return slugg(term);
}
Expand Down Expand Up @@ -259,10 +272,10 @@ module.exports = (function() {
global.settings.cacheDirname,
"_medias"
);
fs.mkdirp(cachePath, function() {
fs.mkdirp(cachePath, function () {
let pathToTempMedia = path.join(cachePath, mediaName);

fs.writeFile(pathToTempMedia, fileBuffer, function(err) {
fs.writeFile(pathToTempMedia, fileBuffer, function (err) {
if (err) reject(err);

let pathToMedia = path.join(getFolderPath(slugFolderName), mediaName);
Expand Down Expand Up @@ -294,9 +307,9 @@ module.exports = (function() {
global.settings.cacheDirname,
"_medias"
);
fs.mkdirp(cachePath, function() {
fs.mkdirp(cachePath, function () {
let pathToMedia = path.join(getFolderPath(slugFolderName), mediaName);
fs.writeFile(pathToMedia, fileBuffer, function(err) {
fs.writeFile(pathToMedia, fileBuffer, function (err) {
if (err) reject(err);
resolve();
});
Expand Down Expand Up @@ -327,7 +340,7 @@ module.exports = (function() {
images,
slugStopmotionName,
frameRate,
socket
socket,
}) {
return new Promise(function(resolve, reject) {
dev.logfunction("COMMON — makeStopmotionFromImageSequence");
Expand All @@ -336,12 +349,12 @@ module.exports = (function() {

_getImageResolution({
slugStopmotionName,
image_filename: images[0]
}).then(resolution => {
image_filename: images[0],
}).then((resolution) => {
_copyToTempAndRenameImages({ slugStopmotionName, images })
.then(tempFolder => {
.then((tempFolder) => {
// ask ffmpeg to make a video from the cache images
const ffmpeg_cmd = new ffmpeg()
const ffmpeg_cmd = new ffmpeg(global.settings.ffmpeg_options)
.input(path.join(tempFolder, "img-%04d.jpeg"))
.inputFPS(frameRate)
.withVideoCodec("libx264")
Expand All @@ -354,22 +367,22 @@ module.exports = (function() {
.autopad()
.addOptions(["-preset slow", "-tune animation"])
.toFormat("mp4")
.on("start", function(commandLine) {
.on("start", function (commandLine) {
dev.logverbose("Spawned Ffmpeg with command: " + commandLine);
})
.on("progress", progress => {
.on("progress", (progress) => {
require("./sockets").notify({
socket,
localized_string: `creating_video`,
not_localized_string:
Number.parseFloat(progress.percent).toFixed(1) + "%"
Number.parseFloat(progress.percent).toFixed(1) + "%",
});
})
.on("end", () => {
dev.logverbose(`Stopmotion has been completed`);
resolve();
})
.on("error", function(err, stdout, stderr) {
.on("error", function (err, stdout, stderr) {
dev.error("An error happened: " + err.message);
dev.error("ffmpeg standard output:\n" + stdout);
dev.error("ffmpeg standard error:\n" + stderr);
Expand All @@ -378,13 +391,13 @@ module.exports = (function() {
.save(pathToMedia);
global.ffmpeg_processes.push(ffmpeg_cmd);
})
.catch(err => reject(err));
.catch((err) => reject(err));
});
});
}

function _copyToTempAndRenameImages({ slugStopmotionName, images }) {
return new Promise(function(resolve, reject) {
return new Promise(function (resolve, reject) {
let cacheFolderName =
getCurrentDate(global.settings.metaDateFormat) +
slugStopmotionName +
Expand All @@ -399,7 +412,7 @@ module.exports = (function() {

fs.mkdirp(
cachePath,
function() {
function () {
let slugStopmotionPath = getFolderPath(
path.join(
global.settings.structure["stopmotions"].path,
Expand All @@ -423,7 +436,7 @@ module.exports = (function() {
.then(() => {
resolve();
})
.catch(err => {
.catch((err) => {
dev.error(`Failed to copy image to cache with seq name.`);
reject(err);
});
Expand All @@ -432,10 +445,10 @@ module.exports = (function() {

Promise.all(tasks)
.then(() => resolve(cachePath))
.catch(err => reject(err));
.catch((err) => reject(err));
});
},
function(err, p) {
function (err, p) {
dev.error(`Failed to create cache folder: ${err}`);
reject(err);
}
Expand All @@ -444,7 +457,7 @@ module.exports = (function() {
}

function _getImageResolution({ slugStopmotionName, image_filename }) {
return new Promise(function(resolve, reject) {
return new Promise(function (resolve, reject) {
let slugStopmotionPath = getFolderPath(
path.join(
global.settings.structure["stopmotions"].path,
Expand All @@ -458,7 +471,7 @@ module.exports = (function() {
if (err) return reject(err);
return resolve({
width: info.width,
height: info.height
height: info.height,
});
});
});
Expand Down
Loading

0 comments on commit 56d440d

Please sign in to comment.