mirror of
https://github.com/KevinMidboe/zoff.git
synced 2026-01-11 12:05:34 +00:00
add comment cleanup and add globals
This commit is contained in:
@@ -1,3 +1,7 @@
|
||||
import {
|
||||
pathThumbnails
|
||||
} from "../settings/globals";
|
||||
|
||||
var express = require("express");
|
||||
var router = express.Router();
|
||||
var path = require("path");
|
||||
@@ -21,15 +25,17 @@ var ObjectId = mongojs.ObjectId;
|
||||
var sIO = require(path.join(__dirname, "../../apps/client.js")).socketIO;
|
||||
var projects = require(pathThumbnails + "/handlers/aggregates.js");
|
||||
|
||||
router.use(function(req, res, next) {
|
||||
router.use(function (req, res, next) {
|
||||
next(); // make sure we go to the next routes and don't stop here
|
||||
});
|
||||
|
||||
router.route("/api/lists").get(function(req, res) {
|
||||
router.route("/api/lists").get(function (req, res) {
|
||||
if (req.isAuthenticated()) {
|
||||
db.collection("frontpage_lists")
|
||||
.find()
|
||||
.sort({ count: -1 }, function(err, docs) {
|
||||
.sort({
|
||||
count: -1
|
||||
}, function (err, docs) {
|
||||
res.json(docs);
|
||||
});
|
||||
} else {
|
||||
@@ -37,9 +43,9 @@ router.route("/api/lists").get(function(req, res) {
|
||||
}
|
||||
});
|
||||
|
||||
router.route("/api/thumbnails").get(function(req, res) {
|
||||
router.route("/api/thumbnails").get(function (req, res) {
|
||||
if (req.isAuthenticated()) {
|
||||
db.collection("suggested_thumbnails").find(function(err, docs) {
|
||||
db.collection("suggested_thumbnails").find(function (err, docs) {
|
||||
res.json(docs);
|
||||
});
|
||||
} else {
|
||||
@@ -47,9 +53,9 @@ router.route("/api/thumbnails").get(function(req, res) {
|
||||
}
|
||||
});
|
||||
|
||||
router.route("/api/descriptions").get(function(req, res) {
|
||||
router.route("/api/descriptions").get(function (req, res) {
|
||||
if (req.isAuthenticated()) {
|
||||
db.collection("suggested_descriptions").find(function(err, docs) {
|
||||
db.collection("suggested_descriptions").find(function (err, docs) {
|
||||
res.json(docs);
|
||||
});
|
||||
} else {
|
||||
@@ -57,9 +63,9 @@ router.route("/api/descriptions").get(function(req, res) {
|
||||
}
|
||||
});
|
||||
|
||||
router.route("/api/rules").get(function(req, res) {
|
||||
router.route("/api/rules").get(function (req, res) {
|
||||
if (req.isAuthenticated()) {
|
||||
db.collection("suggested_rules").find(function(err, docs) {
|
||||
db.collection("suggested_rules").find(function (err, docs) {
|
||||
res.json(docs);
|
||||
});
|
||||
} else {
|
||||
@@ -67,30 +73,44 @@ router.route("/api/rules").get(function(req, res) {
|
||||
}
|
||||
});
|
||||
|
||||
router.route("/api/approve_thumbnail").post(function(req, res) {
|
||||
router.route("/api/approve_thumbnail").post(function (req, res) {
|
||||
if (req.isAuthenticated()) {
|
||||
var channel = req.body.channel;
|
||||
db.collection("suggested_thumbnails").find({ channel: channel }, function(
|
||||
db.collection("suggested_thumbnails").find({
|
||||
channel: channel
|
||||
}, function (
|
||||
err,
|
||||
docs
|
||||
) {
|
||||
var thumbnail = docs[0].thumbnail;
|
||||
db.collection("frontpage_lists").update(
|
||||
{ _id: channel },
|
||||
{ $set: { thumbnail: thumbnail } },
|
||||
{ upsert: true },
|
||||
function(err, docs) {
|
||||
db.collection(channel + "_settings").update(
|
||||
{ views: { $exists: true } },
|
||||
{ $set: { thumbnail: thumbnail } },
|
||||
{ upsert: true },
|
||||
function(err, docs) {
|
||||
db.collection("suggested_thumbnails").remove(
|
||||
{ channel: channel },
|
||||
function(err, docs) {
|
||||
db.collection("frontpage_lists").update({
|
||||
_id: channel
|
||||
}, {
|
||||
$set: {
|
||||
thumbnail: thumbnail
|
||||
}
|
||||
}, {
|
||||
upsert: true
|
||||
},
|
||||
function (err, docs) {
|
||||
db.collection(channel + "_settings").update({
|
||||
views: {
|
||||
$exists: true
|
||||
}
|
||||
}, {
|
||||
$set: {
|
||||
thumbnail: thumbnail
|
||||
}
|
||||
}, {
|
||||
upsert: true
|
||||
},
|
||||
function (err, docs) {
|
||||
db.collection("suggested_thumbnails").remove({
|
||||
channel: channel
|
||||
},
|
||||
function (err, docs) {
|
||||
db.collection(channel + "_settings").aggregate(
|
||||
[
|
||||
{
|
||||
[{
|
||||
$match: {
|
||||
id: "config"
|
||||
}
|
||||
@@ -99,7 +119,7 @@ router.route("/api/approve_thumbnail").post(function(req, res) {
|
||||
$project: projects.toShowConfig
|
||||
}
|
||||
],
|
||||
function(err, docs) {
|
||||
function (err, docs) {
|
||||
if (docs[0].adminpass !== "") docs[0].adminpass = true;
|
||||
if (
|
||||
docs[0].hasOwnProperty("userpass") &&
|
||||
@@ -123,10 +143,12 @@ router.route("/api/approve_thumbnail").post(function(req, res) {
|
||||
}
|
||||
});
|
||||
|
||||
router.route("/api/deny_thumbnail").post(function(req, res) {
|
||||
router.route("/api/deny_thumbnail").post(function (req, res) {
|
||||
if (req.isAuthenticated()) {
|
||||
var channel = req.body.channel;
|
||||
db.collection("suggested_thumbnails").remove({ channel: channel }, function(
|
||||
db.collection("suggested_thumbnails").remove({
|
||||
channel: channel
|
||||
}, function (
|
||||
err,
|
||||
docs
|
||||
) {
|
||||
@@ -137,25 +159,34 @@ router.route("/api/deny_thumbnail").post(function(req, res) {
|
||||
}
|
||||
});
|
||||
|
||||
router.route("/api/approve_rules").post(function(req, res) {
|
||||
router.route("/api/approve_rules").post(function (req, res) {
|
||||
if (req.isAuthenticated()) {
|
||||
var channel = req.body.channel;
|
||||
db.collection("suggested_rules").find({ channel: channel }, function(
|
||||
db.collection("suggested_rules").find({
|
||||
channel: channel
|
||||
}, function (
|
||||
err,
|
||||
docs
|
||||
) {
|
||||
var rules = docs[0].rules;
|
||||
db.collection(channel + "_settings").update(
|
||||
{ views: { $exists: true } },
|
||||
{ $set: { rules: rules } },
|
||||
{ upsert: true },
|
||||
function(err, docs) {
|
||||
db.collection("suggested_rules").remove(
|
||||
{ channel: channel },
|
||||
function(err, docs) {
|
||||
db.collection(channel + "_settings").update({
|
||||
views: {
|
||||
$exists: true
|
||||
}
|
||||
}, {
|
||||
$set: {
|
||||
rules: rules
|
||||
}
|
||||
}, {
|
||||
upsert: true
|
||||
},
|
||||
function (err, docs) {
|
||||
db.collection("suggested_rules").remove({
|
||||
channel: channel
|
||||
},
|
||||
function (err, docs) {
|
||||
db.collection(channel + "_settings").aggregate(
|
||||
[
|
||||
{
|
||||
[{
|
||||
$match: {
|
||||
id: "config"
|
||||
}
|
||||
@@ -164,7 +195,7 @@ router.route("/api/approve_rules").post(function(req, res) {
|
||||
$project: projects.toShowConfig
|
||||
}
|
||||
],
|
||||
function(err, docs) {
|
||||
function (err, docs) {
|
||||
if (docs[0].adminpass !== "") docs[0].adminpass = true;
|
||||
if (
|
||||
docs[0].hasOwnProperty("userpass") &&
|
||||
@@ -186,10 +217,12 @@ router.route("/api/approve_rules").post(function(req, res) {
|
||||
}
|
||||
});
|
||||
|
||||
router.route("/api/deny_rules").post(function(req, res) {
|
||||
router.route("/api/deny_rules").post(function (req, res) {
|
||||
if (req.isAuthenticated()) {
|
||||
var channel = req.body.channel;
|
||||
db.collection("suggested_rules").remove({ channel: channel }, function(
|
||||
db.collection("suggested_rules").remove({
|
||||
channel: channel
|
||||
}, function (
|
||||
err,
|
||||
docs
|
||||
) {
|
||||
@@ -200,16 +233,21 @@ router.route("/api/deny_rules").post(function(req, res) {
|
||||
}
|
||||
});
|
||||
|
||||
router.route("/api/remove_rules").post(function(req, res) {
|
||||
router.route("/api/remove_rules").post(function (req, res) {
|
||||
if (req.isAuthenticated()) {
|
||||
var channel = req.body.channel;
|
||||
db.collection(channel + "_settings").update(
|
||||
{ views: { $exists: true } },
|
||||
{ $set: { rules: "" } },
|
||||
function(err, docs) {
|
||||
db.collection(channel + "_settings").update({
|
||||
views: {
|
||||
$exists: true
|
||||
}
|
||||
}, {
|
||||
$set: {
|
||||
rules: ""
|
||||
}
|
||||
},
|
||||
function (err, docs) {
|
||||
db.collection(channel + "_settings").aggregate(
|
||||
[
|
||||
{
|
||||
[{
|
||||
$match: {
|
||||
id: "config"
|
||||
}
|
||||
@@ -218,7 +256,7 @@ router.route("/api/remove_rules").post(function(req, res) {
|
||||
$project: projects.toShowConfig
|
||||
}
|
||||
],
|
||||
function(err, docs) {
|
||||
function (err, docs) {
|
||||
if (docs[0].adminpass !== "") docs[0].adminpass = true;
|
||||
if (docs[0].hasOwnProperty("userpass") && docs[0].userpass != "")
|
||||
docs[0].userpass = true;
|
||||
@@ -234,29 +272,42 @@ router.route("/api/remove_rules").post(function(req, res) {
|
||||
}
|
||||
});
|
||||
|
||||
router.route("/api/approve_description").post(function(req, res) {
|
||||
router.route("/api/approve_description").post(function (req, res) {
|
||||
if (req.isAuthenticated()) {
|
||||
var channel = req.body.channel;
|
||||
db.collection("suggested_descriptions").find({ channel: channel }, function(
|
||||
db.collection("suggested_descriptions").find({
|
||||
channel: channel
|
||||
}, function (
|
||||
err,
|
||||
docs
|
||||
) {
|
||||
var description = docs[0].description;
|
||||
db.collection("frontpage_lists").update(
|
||||
{ _id: channel },
|
||||
{ $set: { description: description } },
|
||||
{ upsert: true },
|
||||
function(err, docs) {
|
||||
db.collection(channel + "_settings").update(
|
||||
{ views: { $exists: true } },
|
||||
{ $set: { description: description } },
|
||||
function(err, docs) {
|
||||
db.collection("suggested_descriptions").remove(
|
||||
{ channel: channel },
|
||||
function(err, docs) {
|
||||
db.collection("frontpage_lists").update({
|
||||
_id: channel
|
||||
}, {
|
||||
$set: {
|
||||
description: description
|
||||
}
|
||||
}, {
|
||||
upsert: true
|
||||
},
|
||||
function (err, docs) {
|
||||
db.collection(channel + "_settings").update({
|
||||
views: {
|
||||
$exists: true
|
||||
}
|
||||
}, {
|
||||
$set: {
|
||||
description: description
|
||||
}
|
||||
},
|
||||
function (err, docs) {
|
||||
db.collection("suggested_descriptions").remove({
|
||||
channel: channel
|
||||
},
|
||||
function (err, docs) {
|
||||
db.collection(channel + "_settings").aggregate(
|
||||
[
|
||||
{
|
||||
[{
|
||||
$match: {
|
||||
id: "config"
|
||||
}
|
||||
@@ -265,7 +316,7 @@ router.route("/api/approve_description").post(function(req, res) {
|
||||
$project: projects.toShowConfig
|
||||
}
|
||||
],
|
||||
function(err, docs) {
|
||||
function (err, docs) {
|
||||
if (docs[0].adminpass !== "") docs[0].adminpass = true;
|
||||
if (
|
||||
docs[0].hasOwnProperty("userpass") &&
|
||||
@@ -289,13 +340,14 @@ router.route("/api/approve_description").post(function(req, res) {
|
||||
}
|
||||
});
|
||||
|
||||
router.route("/api/deny_description").post(function(req, res) {
|
||||
router.route("/api/deny_description").post(function (req, res) {
|
||||
if (req.isAuthenticated()) {
|
||||
var channel = req.body.channel;
|
||||
db.collection("suggested_descriptions").remove(
|
||||
{ channel: channel },
|
||||
db.collection("suggested_descriptions").remove({
|
||||
channel: channel
|
||||
},
|
||||
1,
|
||||
function(err, docs) {
|
||||
function (err, docs) {
|
||||
res.send(true);
|
||||
}
|
||||
);
|
||||
@@ -304,20 +356,29 @@ router.route("/api/deny_description").post(function(req, res) {
|
||||
}
|
||||
});
|
||||
|
||||
router.route("/api/remove_thumbnail").post(function(req, res) {
|
||||
router.route("/api/remove_thumbnail").post(function (req, res) {
|
||||
if (req.isAuthenticated()) {
|
||||
var channel = req.body.channel;
|
||||
db.collection("frontpage_lists").update(
|
||||
{ _id: channel },
|
||||
{ $set: { thumbnail: "" } },
|
||||
function(err, docs) {
|
||||
db.collection(channel + "_settings").update(
|
||||
{ views: { $exists: true } },
|
||||
{ $set: { thumbnail: "" } },
|
||||
function(err, docs) {
|
||||
db.collection("frontpage_lists").update({
|
||||
_id: channel
|
||||
}, {
|
||||
$set: {
|
||||
thumbnail: ""
|
||||
}
|
||||
},
|
||||
function (err, docs) {
|
||||
db.collection(channel + "_settings").update({
|
||||
views: {
|
||||
$exists: true
|
||||
}
|
||||
}, {
|
||||
$set: {
|
||||
thumbnail: ""
|
||||
}
|
||||
},
|
||||
function (err, docs) {
|
||||
db.collection(channel + "_settings").aggregate(
|
||||
[
|
||||
{
|
||||
[{
|
||||
$match: {
|
||||
id: "config"
|
||||
}
|
||||
@@ -326,7 +387,7 @@ router.route("/api/remove_thumbnail").post(function(req, res) {
|
||||
$project: projects.toShowConfig
|
||||
}
|
||||
],
|
||||
function(err, docs) {
|
||||
function (err, docs) {
|
||||
if (docs[0].adminpass !== "") docs[0].adminpass = true;
|
||||
if (
|
||||
docs[0].hasOwnProperty("userpass") &&
|
||||
@@ -347,20 +408,29 @@ router.route("/api/remove_thumbnail").post(function(req, res) {
|
||||
}
|
||||
});
|
||||
|
||||
router.route("/api/remove_description").post(function(req, res) {
|
||||
router.route("/api/remove_description").post(function (req, res) {
|
||||
if (req.isAuthenticated()) {
|
||||
var channel = req.body.channel;
|
||||
db.collection("frontpage_lists").update(
|
||||
{ _id: channel },
|
||||
{ $set: { description: "" } },
|
||||
function(err, docs) {
|
||||
db.collection(channel + "_settings").update(
|
||||
{ views: { $exists: true } },
|
||||
{ $set: { description: "" } },
|
||||
function(err, docs) {
|
||||
db.collection("frontpage_lists").update({
|
||||
_id: channel
|
||||
}, {
|
||||
$set: {
|
||||
description: ""
|
||||
}
|
||||
},
|
||||
function (err, docs) {
|
||||
db.collection(channel + "_settings").update({
|
||||
views: {
|
||||
$exists: true
|
||||
}
|
||||
}, {
|
||||
$set: {
|
||||
description: ""
|
||||
}
|
||||
},
|
||||
function (err, docs) {
|
||||
db.collection(channel + "_settings").aggregate(
|
||||
[
|
||||
{
|
||||
[{
|
||||
$match: {
|
||||
id: "config"
|
||||
}
|
||||
@@ -369,7 +439,7 @@ router.route("/api/remove_description").post(function(req, res) {
|
||||
$project: projects.toShowConfig
|
||||
}
|
||||
],
|
||||
function(err, docs) {
|
||||
function (err, docs) {
|
||||
if (docs[0].adminpass !== "") docs[0].adminpass = true;
|
||||
if (
|
||||
docs[0].hasOwnProperty("userpass") &&
|
||||
@@ -390,12 +460,17 @@ router.route("/api/remove_description").post(function(req, res) {
|
||||
}
|
||||
});
|
||||
|
||||
router.route("/api/names").get(function(req, res) {
|
||||
router.route("/api/names").get(function (req, res) {
|
||||
if (req.isAuthenticated()) {
|
||||
db.collection("registered_users").find(
|
||||
{ _id: { $exists: true } },
|
||||
{ _id: 1, icon: 1 },
|
||||
function(err, docs) {
|
||||
db.collection("registered_users").find({
|
||||
_id: {
|
||||
$exists: true
|
||||
}
|
||||
}, {
|
||||
_id: 1,
|
||||
icon: 1
|
||||
},
|
||||
function (err, docs) {
|
||||
res.json(docs);
|
||||
}
|
||||
);
|
||||
@@ -404,14 +479,18 @@ router.route("/api/names").get(function(req, res) {
|
||||
}
|
||||
});
|
||||
|
||||
router.route("/api/names").post(function(req, res) {
|
||||
router.route("/api/names").post(function (req, res) {
|
||||
if (req.isAuthenticated()) {
|
||||
var icon = req.body.icon;
|
||||
var name = req.body.name;
|
||||
db.collection("registered_users").update(
|
||||
{ _id: name },
|
||||
{ $set: { icon: icon } },
|
||||
function(err, docs) {
|
||||
db.collection("registered_users").update({
|
||||
_id: name
|
||||
}, {
|
||||
$set: {
|
||||
icon: icon
|
||||
}
|
||||
},
|
||||
function (err, docs) {
|
||||
if (err) res.send(false);
|
||||
else res.send(true);
|
||||
}
|
||||
@@ -421,10 +500,12 @@ router.route("/api/names").post(function(req, res) {
|
||||
}
|
||||
});
|
||||
|
||||
router.route("/api/names").delete(function(req, res) {
|
||||
router.route("/api/names").delete(function (req, res) {
|
||||
if (req.isAuthenticated()) {
|
||||
var name = req.body.name;
|
||||
db.collection("registered_users").remove({ _id: name }, function(
|
||||
db.collection("registered_users").remove({
|
||||
_id: name
|
||||
}, function (
|
||||
err,
|
||||
docs
|
||||
) {
|
||||
@@ -436,17 +517,23 @@ router.route("/api/names").delete(function(req, res) {
|
||||
}
|
||||
});
|
||||
|
||||
router.route("/api/token").get(function(req, res) {
|
||||
router.route("/api/token").get(function (req, res) {
|
||||
if (req.isAuthenticated()) {
|
||||
token_db.collection("tokens").find(function(err, docs) {
|
||||
token_db.collection("tokens").find(function (err, docs) {
|
||||
if (docs.length == 1) {
|
||||
res.json({ token: docs[0].token });
|
||||
res.json({
|
||||
token: docs[0].token
|
||||
});
|
||||
} else {
|
||||
var id = new Buffer(makeid()).toString("base64");
|
||||
token_db
|
||||
.collection("tokens")
|
||||
.insert({ token: id }, function(err, docs) {
|
||||
res.json({ token: id });
|
||||
.insert({
|
||||
token: id
|
||||
}, function (err, docs) {
|
||||
res.json({
|
||||
token: id
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -455,11 +542,15 @@ router.route("/api/token").get(function(req, res) {
|
||||
}
|
||||
});
|
||||
|
||||
router.route("/api/api_token").get(function(req, res) {
|
||||
router.route("/api/api_token").get(function (req, res) {
|
||||
if (req.isAuthenticated()) {
|
||||
token_db
|
||||
.collection("api_token")
|
||||
.find({ token: { $exists: true } }, function(err, all) {
|
||||
.find({
|
||||
token: {
|
||||
$exists: true
|
||||
}
|
||||
}, function (err, all) {
|
||||
res.json(all);
|
||||
});
|
||||
} else {
|
||||
@@ -467,12 +558,14 @@ router.route("/api/api_token").get(function(req, res) {
|
||||
}
|
||||
});
|
||||
|
||||
router.route("/api/api_token").delete(function(req, res) {
|
||||
router.route("/api/api_token").delete(function (req, res) {
|
||||
if (req.isAuthenticated()) {
|
||||
var id = req.body.id;
|
||||
token_db
|
||||
.collection("api_token")
|
||||
.remove({ _id: ObjectId(id) }, function(err, success) {
|
||||
.remove({
|
||||
_id: ObjectId(id)
|
||||
}, function (err, success) {
|
||||
if (err) {
|
||||
res.send("failed");
|
||||
return;
|
||||
@@ -482,7 +575,7 @@ router.route("/api/api_token").delete(function(req, res) {
|
||||
}
|
||||
});
|
||||
|
||||
router.route("/api/api_token").put(function(req, res) {
|
||||
router.route("/api/api_token").put(function (req, res) {
|
||||
if (req.isAuthenticated()) {
|
||||
var id = req.body.id;
|
||||
var limit = req.body.limit;
|
||||
@@ -492,7 +585,13 @@ router.route("/api/api_token").put(function(req, res) {
|
||||
}
|
||||
token_db
|
||||
.collection("api_token")
|
||||
.update({ _id: ObjectId(id) }, { $set: { limit: limit } }, function(
|
||||
.update({
|
||||
_id: ObjectId(id)
|
||||
}, {
|
||||
$set: {
|
||||
limit: limit
|
||||
}
|
||||
}, function (
|
||||
err,
|
||||
success
|
||||
) {
|
||||
@@ -505,7 +604,7 @@ router.route("/api/api_token").put(function(req, res) {
|
||||
}
|
||||
});
|
||||
|
||||
router.route("/api/api_token").post(function(req, res) {
|
||||
router.route("/api/api_token").post(function (req, res) {
|
||||
if (req.isAuthenticated()) {
|
||||
var name = req.body.name;
|
||||
var id = crypto
|
||||
@@ -514,9 +613,18 @@ router.route("/api/api_token").post(function(req, res) {
|
||||
.digest("base64");
|
||||
token_db
|
||||
.collection("api_token")
|
||||
.insert({ name: name, token: id, usage: 0 }, function(err, docs) {
|
||||
token_db.collection("api_token").find({ token: id }, function(err, d) {
|
||||
res.json({ token: id, _id: d[0]._id });
|
||||
.insert({
|
||||
name: name,
|
||||
token: id,
|
||||
usage: 0
|
||||
}, function (err, docs) {
|
||||
token_db.collection("api_token").find({
|
||||
token: id
|
||||
}, function (err, d) {
|
||||
res.json({
|
||||
token: id,
|
||||
_id: d[0]._id
|
||||
});
|
||||
});
|
||||
});
|
||||
} else {
|
||||
@@ -524,12 +632,14 @@ router.route("/api/api_token").post(function(req, res) {
|
||||
}
|
||||
});
|
||||
|
||||
router.route("/api/delete").post(function(req, res) {
|
||||
router.route("/api/delete").post(function (req, res) {
|
||||
if (req.isAuthenticated()) {
|
||||
var list = req.body._id;
|
||||
db.collection(list).drop(function(err, docs) {
|
||||
db.collection(list + "_settings").drop(function(err, docs) {
|
||||
db.collection("frontpage_lists").remove({ _id: list }, function(
|
||||
db.collection(list).drop(function (err, docs) {
|
||||
db.collection(list + "_settings").drop(function (err, docs) {
|
||||
db.collection("frontpage_lists").remove({
|
||||
_id: list
|
||||
}, function (
|
||||
err,
|
||||
docs
|
||||
) {
|
||||
@@ -542,13 +652,15 @@ router.route("/api/delete").post(function(req, res) {
|
||||
}
|
||||
});
|
||||
|
||||
router.route("/api/remove_token").get(function(req, res) {
|
||||
router.route("/api/remove_token").get(function (req, res) {
|
||||
if (req.isAuthenticated()) {
|
||||
token_db.collection("tokens").find(function(err, docs) {
|
||||
token_db.collection("tokens").find(function (err, docs) {
|
||||
if (docs.length == 1) {
|
||||
token_db
|
||||
.collection("tokens")
|
||||
.remove({ token: docs[0].token }, function(err, docs) {
|
||||
.remove({
|
||||
token: docs[0].token
|
||||
}, function (err, docs) {
|
||||
res.send(true);
|
||||
});
|
||||
} else {
|
||||
@@ -560,17 +672,25 @@ router.route("/api/remove_token").get(function(req, res) {
|
||||
}
|
||||
});
|
||||
|
||||
router.route("/api/pinned").post(function(req, res) {
|
||||
router.route("/api/pinned").post(function (req, res) {
|
||||
if (req.isAuthenticated()) {
|
||||
var to_pin = req.body._id;
|
||||
db.collection("frontpage_lists").update(
|
||||
{ pinned: 1 },
|
||||
{ $set: { pinned: 0 } },
|
||||
function(err, resp) {
|
||||
db.collection("frontpage_lists").update(
|
||||
{ _id: to_pin },
|
||||
{ $set: { pinned: 1 } },
|
||||
function(err, resp) {
|
||||
db.collection("frontpage_lists").update({
|
||||
pinned: 1
|
||||
}, {
|
||||
$set: {
|
||||
pinned: 0
|
||||
}
|
||||
},
|
||||
function (err, resp) {
|
||||
db.collection("frontpage_lists").update({
|
||||
_id: to_pin
|
||||
}, {
|
||||
$set: {
|
||||
pinned: 1
|
||||
}
|
||||
},
|
||||
function (err, resp) {
|
||||
res.send(true);
|
||||
}
|
||||
);
|
||||
@@ -581,13 +701,19 @@ router.route("/api/pinned").post(function(req, res) {
|
||||
}
|
||||
});
|
||||
|
||||
router.route("/api/admin").post(function(req, res) {
|
||||
router.route("/api/admin").post(function (req, res) {
|
||||
if (req.isAuthenticated()) {
|
||||
var to_remove = req.body._id;
|
||||
db.collection(to_remove + "_settings").update(
|
||||
{ views: { $exists: true } },
|
||||
{ $set: { adminpass: "" } },
|
||||
function(err, docs) {
|
||||
db.collection(to_remove + "_settings").update({
|
||||
views: {
|
||||
$exists: true
|
||||
}
|
||||
}, {
|
||||
$set: {
|
||||
adminpass: ""
|
||||
}
|
||||
},
|
||||
function (err, docs) {
|
||||
res.send(true);
|
||||
}
|
||||
);
|
||||
@@ -596,13 +722,19 @@ router.route("/api/admin").post(function(req, res) {
|
||||
}
|
||||
});
|
||||
|
||||
router.route("/api/userpass").post(function(req, res) {
|
||||
router.route("/api/userpass").post(function (req, res) {
|
||||
if (req.isAuthenticated()) {
|
||||
var to_remove = req.body._id;
|
||||
db.collection(to_remove + "_settings").update(
|
||||
{ views: { $exists: true } },
|
||||
{ $set: { userpass: "" } },
|
||||
function(err, docs) {
|
||||
db.collection(to_remove + "_settings").update({
|
||||
views: {
|
||||
$exists: true
|
||||
}
|
||||
}, {
|
||||
$set: {
|
||||
userpass: ""
|
||||
}
|
||||
},
|
||||
function (err, docs) {
|
||||
res.send(true);
|
||||
}
|
||||
);
|
||||
@@ -622,4 +754,4 @@ function makeid() {
|
||||
return text;
|
||||
}
|
||||
|
||||
module.exports = router;
|
||||
module.exports = router;
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,27 +1,32 @@
|
||||
import {
|
||||
pathThumbnails
|
||||
} from "../settings/globals";
|
||||
|
||||
|
||||
var express = require("express");
|
||||
const path = require("path");
|
||||
var router = express.Router();
|
||||
router.use(function(req, res, next) {
|
||||
router.use(function (req, res, next) {
|
||||
next(); // make sure we go to the next routes and don't stop here
|
||||
});
|
||||
|
||||
router.route("/favicon.ico").get(function(req, res, next) {
|
||||
router.route("/favicon.ico").get(function (req, res, next) {
|
||||
res.sendFile(path.join(pathThumbnails, "/public/assets/images/favicon.ico"));
|
||||
});
|
||||
|
||||
router.route("/browserconfig.xml").get(function(req, res, next) {
|
||||
router.route("/browserconfig.xml").get(function (req, res, next) {
|
||||
res.sendFile(
|
||||
path.join(pathThumbnails, "/public/assets/images/browserconfig.xml")
|
||||
);
|
||||
});
|
||||
|
||||
router.route("/apple-touch-icon.png").get(function(req, res, next) {
|
||||
router.route("/apple-touch-icon.png").get(function (req, res, next) {
|
||||
res.sendFile(
|
||||
path.join(pathThumbnails, "/public/assets/images/apple-touch-icon.png")
|
||||
);
|
||||
});
|
||||
|
||||
router.route("/apple-touch-icon-precomposed.png").get(function(req, res, next) {
|
||||
router.route("/apple-touch-icon-precomposed.png").get(function (req, res, next) {
|
||||
res.sendFile(
|
||||
path.join(
|
||||
pathThumbnails,
|
||||
@@ -30,4 +35,4 @@ router.route("/apple-touch-icon-precomposed.png").get(function(req, res, next) {
|
||||
);
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
module.exports = router;
|
||||
@@ -1,3 +1,7 @@
|
||||
import {
|
||||
pathThumbnails
|
||||
} from "../settings/globals";
|
||||
|
||||
var express = require("express");
|
||||
var router = express.Router();
|
||||
var path = require("path");
|
||||
@@ -9,7 +13,6 @@ var adsense = "xx";
|
||||
var adds = false;
|
||||
var mongojs = require("mongojs");
|
||||
var token_db = mongojs("tokens");
|
||||
var Functions = require(pathThumbnails + "/handlers/functions.js");
|
||||
var Frontpage = require(pathThumbnails + "/handlers/frontpage.js");
|
||||
|
||||
var db = require(pathThumbnails + "/handlers/db.js");
|
||||
@@ -50,28 +53,28 @@ try {
|
||||
};
|
||||
}
|
||||
|
||||
router.use(recaptcha.middleware.render, function(req, res, next) {
|
||||
router.use(recaptcha.middleware.render, function (req, res, next) {
|
||||
next(); // make sure we go to the next routes and don't stop here
|
||||
});
|
||||
|
||||
router.route("/:channel_name").get(function(req, res, next) {
|
||||
router.route("/:channel_name").get(function (req, res, next) {
|
||||
channel(req, res, next);
|
||||
});
|
||||
|
||||
router.route("/r/:base64data").get(function(req, res, next) {
|
||||
router.route("/r/:base64data").get(function (req, res, next) {
|
||||
var channelToRedirect = Buffer.from(req.params.base64data, "base64");
|
||||
res.redirect("/" + channelToRedirect);
|
||||
});
|
||||
|
||||
router.route("/").get(function(req, res, next) {
|
||||
router.route("/").get(function (req, res, next) {
|
||||
root(req, res, next);
|
||||
});
|
||||
|
||||
router.route("/").post(function(req, res, next) {
|
||||
router.route("/").post(function (req, res, next) {
|
||||
root(req, res, next);
|
||||
});
|
||||
|
||||
router.route("/api/embed").get(function(req, res, next) {
|
||||
router.route("/api/embed").get(function (req, res, next) {
|
||||
var data = {
|
||||
year: year,
|
||||
type: "video",
|
||||
@@ -85,11 +88,11 @@ router.route("/api/embed").get(function(req, res, next) {
|
||||
res.render("layouts/client/embed", data);
|
||||
});
|
||||
|
||||
router.route("/api/oauth").get(function(req, res, next) {
|
||||
router.route("/api/oauth").get(function (req, res, next) {
|
||||
res.sendFile(path.join(pathThumbnails, "/public/assets/html/callback.html"));
|
||||
});
|
||||
|
||||
router.route("/api/apply").get(function(req, res, next) {
|
||||
router.route("/api/apply").get(function (req, res, next) {
|
||||
var data = {
|
||||
year: year,
|
||||
javascript_file: "token.min.js",
|
||||
@@ -108,17 +111,25 @@ router.route("/api/apply").get(function(req, res, next) {
|
||||
res.render("layouts/client/token", data);
|
||||
});
|
||||
|
||||
router.route("/api/apply/:id").get(function(req, res) {
|
||||
router.route("/api/apply/:id").get(function (req, res) {
|
||||
var id = req.params.id;
|
||||
token_db.collection("api_links").find({ id: id }, function(err, result) {
|
||||
token_db.collection("api_links").find({
|
||||
id: id
|
||||
}, function (err, result) {
|
||||
if (result.length == 1) {
|
||||
token_db.collection("api_links").remove({ id: id }, function(e, d) {
|
||||
token_db.collection("api_links").remove({
|
||||
id: id
|
||||
}, function (e, d) {
|
||||
token_db
|
||||
.collection("api_token")
|
||||
.update(
|
||||
{ token: result[0].token },
|
||||
{ $set: { active: true } },
|
||||
function(e, d) {
|
||||
.update({
|
||||
token: result[0].token
|
||||
}, {
|
||||
$set: {
|
||||
active: true
|
||||
}
|
||||
},
|
||||
function (e, d) {
|
||||
var data = {
|
||||
year: year,
|
||||
javascript_file: "token.min.js",
|
||||
@@ -161,12 +172,12 @@ router.route("/api/apply/:id").get(function(req, res) {
|
||||
|
||||
function root(req, res, next) {
|
||||
try {
|
||||
var url = req.headers["x-forwarded-host"]
|
||||
? req.headers["x-forwarded-host"]
|
||||
: req.headers.host.split(":")[0];
|
||||
var subdomain = req.headers["x-forwarded-host"]
|
||||
? req.headers["x-forwarded-host"].split(".")
|
||||
: req.headers.host.split(":")[0].split(".");
|
||||
var url = req.headers["x-forwarded-host"] ?
|
||||
req.headers["x-forwarded-host"] :
|
||||
req.headers.host.split(":")[0];
|
||||
var subdomain = req.headers["x-forwarded-host"] ?
|
||||
req.headers["x-forwarded-host"].split(".") :
|
||||
req.headers.host.split(":")[0].split(".");
|
||||
if (subdomain[0] == "remote") {
|
||||
var data = {
|
||||
year: year,
|
||||
@@ -202,8 +213,10 @@ function root(req, res, next) {
|
||||
if (subdomain[0] == "client") {
|
||||
data.client = true;
|
||||
}
|
||||
Frontpage.get_frontpage_lists(function(err, docs) {
|
||||
db.collection("connected_users").find({ _id: "total_users" }, function(
|
||||
Frontpage.get_frontpage_lists(function (err, docs) {
|
||||
db.collection("connected_users").find({
|
||||
_id: "total_users"
|
||||
}, function (
|
||||
err,
|
||||
tot
|
||||
) {
|
||||
@@ -228,12 +241,12 @@ function root(req, res, next) {
|
||||
|
||||
function channel(req, res, next) {
|
||||
try {
|
||||
var url = req.headers["x-forwarded-host"]
|
||||
? req.headers["x-forwarded-host"]
|
||||
: req.headers.host.split(":")[0];
|
||||
var subdomain = req.headers["x-forwarded-host"]
|
||||
? req.headers["x-forwarded-host"].split(".")
|
||||
: req.headers.host.split(":")[0].split(".");
|
||||
var url = req.headers["x-forwarded-host"] ?
|
||||
req.headers["x-forwarded-host"] :
|
||||
req.headers.host.split(":")[0];
|
||||
var subdomain = req.headers["x-forwarded-host"] ?
|
||||
req.headers["x-forwarded-host"].split(".") :
|
||||
req.headers.host.split(":")[0].split(".");
|
||||
if (subdomain[0] == "remote") {
|
||||
var data = {
|
||||
year: year,
|
||||
@@ -285,4 +298,4 @@ function capitalizeFirstLetter(string) {
|
||||
return string.charAt(0).toUpperCase() + string.slice(1);
|
||||
}
|
||||
|
||||
module.exports = router;
|
||||
module.exports = router;
|
||||
Reference in New Issue
Block a user