Skip to content
Snippets Groups Projects
Commit 417cbeb4 authored by echicken's avatar echicken :chicken:
Browse files

Use require() for request,FileBase. Use 'request' to get query params.

parent 27d96e0d
No related branches found
No related tags found
1 merge request!463MRC mods by Codefenix (2024-10-20)
...@@ -4,41 +4,40 @@ var settings = load('modopts.js', 'web') || { web_directory: '../webv4' }; ...@@ -4,41 +4,40 @@ var settings = load('modopts.js', 'web') || { web_directory: '../webv4' };
load(settings.web_directory + '/lib/init.js'); load(settings.web_directory + '/lib/init.js');
load(settings.web_lib + 'auth.js'); load(settings.web_lib + 'auth.js');
load(settings.web_lib + 'files.js'); load(settings.web_lib + 'files.js');
require('filebase.js', 'FileBase'); var request = require({}, settings.web_lib + 'request.js', 'request');
var Filebase = require({}, 'filebase.js', 'FileBase');
var CHUNK_SIZE = 1024; var CHUNK_SIZE = 1024;
var reply = {}; var reply = {};
if ((http_request.method === 'GET' || http_request.method === 'POST') && if ((http_request.method === 'GET' || http_request.method === 'POST') && request.has_param('call') && user.number > 0) {
typeof http_request.query.call !== 'undefined' && user.number > 0
) {
switch (http_request.query.call[0].toLowerCase()) { switch (request.get_param('call').toLowerCase()) {
case 'download-file': case 'download-file':
if (typeof http_request.query.dir !== 'undefined' && var dir = request.get_param('dir');
typeof file_area.dir[http_request.query.dir[0]] !== 'undefined' && if (dir !== undefined
file_area.dir[http_request.query.dir[0]].lib_index >= 0 && && file_area.dir[dir] !== undefined && file_area.dir[dir].lib_index >= 0 && file_area.dir[dir].index >= 0 && file_area.dir[dir].can_download
file_area.dir[http_request.query.dir[0]].index >= 0 && && request.has_param('file')
file_area.dir[http_request.query.dir[0]].can_download && && user.compare_ars(file_area.dir[dir].download_ars)
typeof http_request.query.file !== 'undefined'
&& user.compare_ars(file_area.dir[http_request.query.dir[0]].download_ars)
) { ) {
var dircode = file_area.dir[http_request.query.dir[0]].code; var dircode = file_area.dir[dir].code;
var fn = request.get_param('file').toLowerCase();
var fileBase = new FileBase(dircode); var fileBase = new FileBase(dircode);
var file = null; var file = null;
fileBase.some(function (e) { fileBase.some(function (e) {
if (e.name.toLowerCase() !== http_request.query.file[0].toLowerCase()) { if (e.name.toLowerCase() !== fn) {
return false; return false;
} else if (typeof e.path !== 'undefined') { } else if (e.path !== undefined) {
file = e; file = e;
return true; return true;
} }
}); });
fileBase = undefined;
if (file === null) { if (file === null) {
reply.error = 'File not found'; reply.error = 'File not found';
break; break;
} }
if (!file_area.dir[dircode].is_exempt && file.credits > (user.security.credits + user.security.free_credits)) { if (!file_area.dir[dir].is_exempt && file.credits > (user.security.credits + user.security.free_credits)) {
reply.error = 'Not enough credits to download this file'; reply.error = 'Not enough credits to download this file';
break; break;
} }
...@@ -64,6 +63,7 @@ if ((http_request.method === 'GET' || http_request.method === 'POST') && ...@@ -64,6 +63,7 @@ if ((http_request.method === 'GET' || http_request.method === 'POST') &&
yield(false); yield(false);
} }
f.close(); f.close();
f = undefined;
reply = false; reply = false;
user.downloaded_file(dircode, file.path); user.downloaded_file(dircode, file.path);
} }
...@@ -80,3 +80,5 @@ reply = JSON.stringify(reply); ...@@ -80,3 +80,5 @@ reply = JSON.stringify(reply);
http_reply.header['Content-Type'] = 'application/json'; http_reply.header['Content-Type'] = 'application/json';
http_reply.header['Content-Length'] = reply.length; http_reply.header['Content-Length'] = reply.length;
write(reply); write(reply);
reply = undefined;
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment