Browse Source

fix cross-filesystem symlink issues

master
poikilos 6 years ago
committed by Jacob Gustafson
parent
commit
1e51a23a3b
  1. 75
      webapp/server.js

75
webapp/server.js

@ -7,15 +7,16 @@
const profilePath = require('os').homedir(); const profilePath = require('os').homedir();
var skinDir = profilePath + "/minetest/games/ENLIVEN/mods/codercore/coderskins/textures"; var minetestPath = profilePath + "/minetest"; // TODO: differs from .minetest if not RUN_IN_PLACE
var skinDir = "";
var tz_offset = 240; //subtract this from server time to get local time; 4hrs is 240; 5hrs is 300 var tz_offset = 240; //subtract this from server time to get local time; 4hrs is 240; 5hrs is 300
//TODO: handle tz_offset not divisible by 60 // TODO: handle tz_offset not divisible by 60
//var selected_date_s = null; // var selected_date_s = null;
//selected_date_s = "2018-05-08"; // selected_date_s = "2018-05-08";
var express = require('express'), var express = require('express'),
//var exphbs = require("express-handlebars"); // var exphbs = require("express-handlebars");
// exphbs = require('../../'); // "express-handlebars" // exphbs = require('../../'); // "express-handlebars"
cookieParser = require('cookie-parser'), cookieParser = require('cookie-parser'),
bodyParser = require('body-parser'), bodyParser = require('body-parser'),
//session = require('express-session'), //session = require('express-session'),
@ -54,6 +55,10 @@ var unique_flags = [
]; ];
//#endregion derived from mtsenliven.py //#endregion derived from mtsenliven.py
function regeneratePaths() {
skinDir = minetestPath + "/games/ENLIVEN/mods/codercore/coderskins/textures";
}
function process_logline(line, line_number) { function process_logline(line, line_number) {
//selected_date_s //selected_date_s
//TODO: use store_unique_log_data instead of this function //TODO: use store_unique_log_data instead of this function
@ -342,28 +347,39 @@ app.post('/set-skin', function (req, res){
destNameNoExt = destNameNoExt = "player_" + fields.userName; destNameNoExt = destNameNoExt = "player_" + fields.userName;
directPath = skinDir + "/" + destNameNoExt + ".png"; directPath = skinDir + "/" + destNameNoExt + ".png";
indirectPath = skinDir + "/" + destNameNoExt + ".skin"; indirectPath = skinDir + "/" + destNameNoExt + ".skin";
// TODO: make sure my_file and project_id values are present // TODO: make sure my_file and userName values are present
if (files.userFile != undefined) { if (files.userFile != undefined) {
var originalPath = files.userFile.path; if (userName != undefined) {
console.log("trying to rename " + files.userFile.path var originalPath = files.userFile.path;
+ " to " + directPath); console.log("trying to rename " + files.userFile.path
fs.rename(files.userFile.path, directPath, function(err) { + " to " + directPath);
if (err) { fs.rename(files.userFile.path, directPath, function(err) {
msg = "Failed to rename " + originalPath if (err) {
+ " to " + directPath + "<br/>\n"; msg = "Failed to rename " + originalPath
console.log(msg); + " to " + directPath;
next(err); console.log(msg);
} msg += "<br/>\n";
else { //next(err);
var thisData = destNameNoExt + ".png"; // TODO: why does next above show:
fs.writeFile(indirectPath, thisData, function(err, data) { //ReferenceError: next is not defined
if (err) console.log(err); //at /home/owner/git/EnlivenMinetest/webapp/server.js:355:6
console.log("Successfully wrote " + thisData //at FSReqWrap.oncomplete (fs.js:135:15)
+ " to "+indirectPath+".");
}); }
} else {
res.end(); var thisData = destNameNoExt + ".png";
}); fs.writeFile(indirectPath, thisData, function(err, data) {
if (err) console.log(err);
console.log("Successfully wrote " + thisData
+ " to "+indirectPath+".");
});
}
res.end();
});
}
else {
console.log("userName is undefined.");
}
} }
else { else {
console.log("userFile is undefined."); console.log("userFile is undefined.");
@ -450,6 +466,11 @@ Your browser does not support the canvas element.
var server = app.listen(3000, function () { var server = app.listen(3000, function () {
//console.log('express-handlebars example server listening on: 3000'); //console.log('express-handlebars example server listening on: 3000');
var thisMinetest = "/tank/local/owner/minetest";
if (fs.existsSync(thisMinetest)) {
minetestPath = thisMinetest;
}
regeneratePaths();
var host = server.address().address; var host = server.address().address;
var port = server.address().port; var port = server.address().port;
console.log("server address:"); console.log("server address:");

Loading…
Cancel
Save