Skip to content

Commit

Permalink
cleanup drag-and-drop
Browse files Browse the repository at this point in the history
  • Loading branch information
benptc committed Jul 17, 2023
1 parent c55585c commit fec7148
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 25 deletions.
21 changes: 8 additions & 13 deletions controllers/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ function uploadMediaFile(objectID, req, callback) {

let form = new formidable.IncomingForm({
uploadDir: mediaDir,
keepExtensions: true
// accept: 'image/jpeg' // TODO: specify which types of images/videos it accepts?
keepExtensions: true,
// accept: 'image/jpeg' // we don't include this anymore, because any filetype can be uploaded
});

console.log('created form');
Expand All @@ -138,27 +138,23 @@ function uploadMediaFile(objectID, req, callback) {
callback(500, err);
});

let mediaUuid = utilities.uuidTime();
let mediaUuid = utilities.uuidTime(); // deprecated
let simplifiedFilename = null;
let newFilepath = null;

form.on('fileBegin', function (name, file) {
console.log('fileBegin loading', name, file);

let filepath = file.path || file.filepath;
// rename uploaded file using mediaUuid that is passed back to client
// let extension = path.extname(filepath);
// simplify the filename so that it only contains alphanumeric, hyphens, underscores, and periods
simplifiedFilename = simplifyFilename(file.originalFilename);
// newFilepath = path.join(form.uploadDir, `${mediaUuid}_${simplifiedFilename}`);
newFilepath = path.join(form.uploadDir, simplifiedFilename);
// newFilepath = form.uploadDir + '/' + mediaUuid + extension;

if (fs.existsSync(newFilepath)) {
console.log('deleted old raw file');
fs.unlinkSync(newFilepath);
}

console.log('upload ' + filepath + ' to ' + newFilepath);
// old formidable library uses file.path, new version uses file.filepath
if (file.path) {
file.path = newFilepath;
} else if (file.filepath) {
Expand All @@ -171,10 +167,9 @@ function uploadMediaFile(objectID, req, callback) {

callback(200, {
success: true,
mediaUuid: mediaUuid,
rawFilepath: newFilepath,
// fileName: `${mediaUuid}_${simplifiedFilename}` // mediaUuid + path.extname(newFilepath)
fileName: simplifiedFilename // mediaUuid + path.extname(newFilepath)
mediaUuid: mediaUuid, // deprecated field
fileName: simplifiedFilename, // the "title" of the file
rawFilepath: newFilepath // this is the actual path to the resource
});
});
}
Expand Down
11 changes: 0 additions & 11 deletions libraries/objectDefaultFiles/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,6 @@
this.setFullScreenOff = makeSendStub('setFullScreenOff');
this.setStickyFullScreenOn = makeSendStub('setStickyFullScreenOn');
this.setStickinessOff = makeSendStub('setStickinessOff');
this.setFull2D = makeSendStub('setFull2D');
this.setExclusiveFullScreenOn = makeSendStub('setExclusiveFullScreenOn');
this.setExclusiveFullScreenOff = makeSendStub('setExclusiveFullScreenOff');
this.isExclusiveFullScreenOccupied = makeSendStub('isExclusiveFullScreenOccupied');
Expand Down Expand Up @@ -1387,16 +1386,6 @@
postDataToParent(dataToPost);
};

/**
* Removes or adds the touch overlay div from the tool, without affecting fullscreen status
* @param {boolean} enabled
*/
this.setFull2D = function (enabled) {
postDataToParent({
full2D: enabled
});
}

this.setStickyFullScreenOn = function (params) {
spatialObject.sendFullScreen = 'sticky';
// console.log(spatialObject.frame + ' fullscreen = ' + spatialObject.sendFullScreen);
Expand Down
3 changes: 2 additions & 1 deletion server.js
Original file line number Diff line number Diff line change
Expand Up @@ -1571,6 +1571,7 @@ function objectWebServer() {
return;
}
var fileName = path.join(frameLibPath, req.originalUrl.split('/frames/')[1]); //__dirname + '/libraries' + req.originalUrl;
// we need to check without any ?options=xyz at the end or it might not find the file
let fileNameWithoutQueryParams = fileName.split('?')[0];
if (!fs.existsSync(fileNameWithoutQueryParams)) {
next();
Expand All @@ -1584,7 +1585,7 @@ function objectWebServer() {
}

// HTML files get object.js injected
var html = fs.readFileSync(fileName, 'utf8');
var html = fs.readFileSync(fileNameWithoutQueryParams, 'utf8');

// remove any hard-coded references to object.js (or object-frames.js) and pep.min.js
html = html.replace('<script src="object.js"></script>', '');
Expand Down

0 comments on commit fec7148

Please sign in to comment.