diff --git a/.gitignore b/.gitignore index 6451580..63aacd7 100644 --- a/.gitignore +++ b/.gitignore @@ -5,7 +5,6 @@ lib/auth.js lib/config.js lib/cwmp.js lib/db.js -lib/fs.js lib/nbi.js lib/query.js lib/server.js diff --git a/lib/fs.coffee b/lib/fs.coffee deleted file mode 100644 index 26f368a..0000000 --- a/lib/fs.coffee +++ /dev/null @@ -1,49 +0,0 @@ -### -# Copyright 2013 Fanoos Telecom -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. -### - -config = require './config' -url = require 'url' -mongodb = require 'mongodb' -querystring = require 'querystring' -db = require './db' - - -listener = (request, response) -> - urlParts = url.parse(request.url, true) - if request.method == 'GET' - filename = querystring.unescape(urlParts.pathname.substring(1)) - gs = new mongodb.GridStore(db.mongoDb, filename, 'r', {}) - gs.open((err, gs) -> - if err - response.writeHead(404) - response.end() - return - stream = gs.stream(true) - response.writeHead(200, {'Content-Type' : 'application/octet-stream', 'Content-Length' : gs.length}) - stream.pipe(response) - ) - else - response.writeHead(405, {'Allow': 'GET'}) - response.end('405 Method Not Allowed') - - -exports.listener = listener diff --git a/lib/fs.js b/lib/fs.js new file mode 100644 index 0000000..c2062ef --- /dev/null +++ b/lib/fs.js @@ -0,0 +1,52 @@ +/** + * Copyright 2013-2018 Zaid Abdulla + * + * This file is part of GenieACS. + * + * GenieACS is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * GenieACS is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with GenieACS. If not, see . + */ +"use strict"; + +const url = require("url"); +const querystring = require("querystring"); +const mongodb = require("mongodb"); +const db = require("./db"); + +function listener(request, response) { + const urlParts = url.parse(request.url, true); + if (request.method === "GET") { + const filename = querystring.unescape(urlParts.pathname.substring(1)); + const gs = new mongodb.GridStore(db.mongoDb, filename, "r", {}); + gs.open((err, gs) => { + if (err) { + response.writeHead(404); + response.end(); + return; + } + const stream = gs.stream(true); + response.writeHead(200, { + "Content-Type": "application/octet-stream", + "Content-Length": gs.length + }); + stream.pipe(response); + }); + } else { + response.writeHead(405, { + "Allow": "GET" + }); + response.end("405 Method Not Allowed"); + } +} + +exports.listener = listener;