Example #1
0
// runs the endpoint
// - endpoint: full path of endpoint e.g. "/lib/getall"
// - query: query object
// - res: response object
function run(endpoint, query, res) {
	// executing command
	switch (endpoint) {
	case '/lib/getall':
		// retrieves library list and information on selected library
		envelope(res, true, function (ok) {
			library.list(function (data) {
				ok(data);
			});
		});
		break;
		
	case '/lib/select':
		// sets the selected library
		envelope(res, true, function (ok) {
			if (!query.name) {
				throw "Missing parameters";
			}
			library.set(query.name, function (data) {
				console.log("library changed");
				ok(data);
			});
		});
		break;

	case '/lib/save':
		// saves library
		if (!query.name) {
			throw "Missing parameters";
		}
		(function () {
			var filePath = $path.join(process.cwd(), 'server/db/' + query.name + '.sqlite');
			file.fetch(filePath, res);
		}());
		break;
		
	default:
		return false;
	}
	
	return true;
}
Example #2
0
// runs the endpoint
// - endpoint: full path of endpoint e.g. "/lib/getall"
// - query: query object
// - res: response object
function run(endpoint, query, res) {
	// executing command
	if (endpoint === '/root/add') {
		// adding path to root collection or library
		envelope(res, true, function (ok) {
			if (!query.path) {
				throw "Missing parameters";
			}
			// adding root path
			library.addRoot(query.path, function () {
				ok(query);
			});
		});
		
		return true;
	} else {
		return false;
	}
}
Example #3
0
// runs the endpoint
// - endpoint: full path of endpoint e.g. "/lib/getall"
// - query: query object
// - res: response object
function run(endpoint, query, res) {
	// executing command
	switch (endpoint) {
	case '/tag/add':
		// deleting tag
		envelope(res, true, function (ok) {
			if (!(query.mediaid || query.mediaids) || !query.tag) {
				throw "Missing parameters";
			}
			tag.add(query, query.mediaids, null, function () {
				ok(query);
			});
		});
		break;

	case '/tag/set':
		// updating tag
		envelope(res, true, function (ok) {
			if (!query.before || !query.after) {
				throw "Missing parameters";
			}
			tag.set(
				query.mediaid ?
					{mediaid: query.mediaid, tag: query.before} :
					{tag: query.before},
				{tag: query.after}, function () {
				ok(query);
			});
		});
		break;		
		
	case '/tag/explode':
		// exploding tag
		envelope(res, true, function (ok) {
			if (!query.tag) {
				throw "Missing parameters";
			}
			tag.explode(query, query.mediaids, function () {
				ok(query);
			});
		});
		break;

	case '/tag/del':
		// deleting tag
		envelope(res, true, function (ok) {
			if (!query.tag) {
				throw "Missing parameters";
			}
			tag.remove(query, query.mediaids, null, function () {
				ok(query);
			});
		});
		break;
				
	default:
		return false;
	}
	
	return true;
}