{"size": 7705, "ext": "js", "max_stars_repo_path": "routes/index.js", "max_stars_repo_name": "Scripler/scripler", "max_stars_repo_stars_event_min_datetime": "2016-07-31T15:58:45.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-13T09:39:57.000Z", "max_issues_repo_path": "routes/index.js", "max_issues_repo_name": "Scripler/scripler", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "routes/index.js", "max_forks_repo_name": "Scripler/scripler", "max_forks_repo_forks_event_min_datetime": "2016-12-14T15:54:02.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-13T09:39:59.000Z"}
{"max_stars_count": 5, "max_issues_count": null, "max_forks_count": 2, "avg_line_length": 53.5069444444, "max_line_length": 136, "alphanum_fraction": 0.7196625568}
var frontpage = require('./frontpage')
	, user = require('./user')
	, project = require('./project')
	, folder = require('./folder')
	, document = require('./document')
	, styleset = require('./styleset')
	, style = require('./style')
	, image = require('./image')
	, font = require('./font')
	, payment = require('./payment')
	, server = require('./server')
	, utils = require('../lib/utils')
	, conf = require('config');

module.exports = function (app, auth) {

	// End-User URLs
	// These routes interact directly with the user (the URLs are seen by the user).
	app.get('/user/sso', user.sso);
	app.get('/user/:id/verify/:hash', user.verify);
	app.get('/logout', frontpage.logout);

	// API URIs
	// The routes below are the URLs used by the API (not the URLs seen by the user).

	/* API Frontpage */
	app.get('/user', auth.isLoggedIn(), user.get);
	app.put('/user', auth.isLoggedIn(), user.edit);
	app.post('/user/login', user.login);
	app.post('/user/logout', user.logout);
	app.post('/user/register', user.register);
	app.post('/user/resend-verify-email', auth.isLoggedIn(), user.resendVerifyEmail);
	app.post('/user/password-reset', user.passwordReset);
	app.post('/user/:id/password-change', user.passwordChange);
	app.get('/user/country', user.getCountry);

	/* API Project Space: Project */
	app.get('/project/list', auth.isLoggedIn(), project.list);
	app.put('/project/rearrange', auth.isLoggedIn(), project.rearrange);
	app.post('/project', auth.isLoggedIn(), project.create);
	app.get('/project/:projectIdPopulated', auth.isLoggedIn(), project.open);
	app.put('/project/:projectId/rename', auth.isLoggedIn(), project.rename);
	app.put('/project/:projectIdNoPremiumCheck/archive', auth.isLoggedIn(), project.archive);
	app.put('/project/:projectIdNoPremiumCheck/unarchive', auth.isLoggedIn(), project.unarchive);
	app.put('/project/:projectId/metadata', auth.isLoggedIn(), project.metadata);
	app.put('/project/:projectId/metadata/cover', auth.isLoggedIn(), project.metadata_cover); // TODO: Refactor when using PATCH, c.f. #323
	app.put('/project/:projectId/toc', auth.isLoggedIn(), project.set_toc);
	app.get('/project/:projectIdPopulatedFull/toc', auth.isLoggedIn(), project.get_toc);
	app.delete('/project/:projectIdNoPremiumCheck', auth.isLoggedIn(), project.delete);
	app.post('/project/:projectIdPopulatedFull/copy', auth.isLoggedIn(), project.copy);
	app.post('/image/:projectId/upload', auth.isLoggedIn(), image.create);
	app.get('/project/:projectId/images/*', auth.isLoggedIn(), image.get);

	/* API Document Manager: Document and Folder */
	app.post('/document', auth.isLoggedIn(), project.load(), document.create);
	app.get('/document/:documentId', auth.isLoggedIn(), document.open);
	app.put('/document/:documentId/update', auth.isLoggedIn(), document.update);
	app.put('/document/:documentId/rename', auth.isLoggedIn(), document.rename);
	app.put('/document/:documentId/archive', auth.isLoggedIn(), document.archive);
	app.put('/document/:documentId/unarchive', auth.isLoggedIn(), document.unarchive);
	app.put('/document/:projectId/rearrange', auth.isLoggedIn(), document.rearrange);
	app.delete('/document/:projectId/:documentId', auth.isLoggedIn(), document.delete);
	app.post('/document/:projectId/upload', auth.isLoggedIn(), document.upload);
	app.post('/folder', auth.isLoggedIn(), project.load(), folder.create);
	app.get('/folder/:projectId/:folderId/:archived?', auth.isLoggedIn(), folder.open);
	app.put('/folder/:id/rename', auth.isLoggedIn(), project.load(), folder.rename);
	app.put('/folder/:projectId/:folderId/archive', auth.isLoggedIn(), folder.archive);
	app.put('/folder/:projectId/:folderId/unarchive', auth.isLoggedIn(), folder.unarchive);
	app.delete('/folder/:projectId/:parentFolderId?/:folderId', auth.isLoggedIn(), folder.delete);

	/* API Typography: Styleset and Style */
	app.get('/styleset/systemlist', auth.isLoggedIn(), styleset.listSystemStylesets); // Currently not used
	app.post('/styleset', auth.isLoggedIn(), styleset.create);
	app.get('/styleset/archived', auth.isLoggedIn(), styleset.archived); // This path must come before paths with variables
	app.get('/style/archived', auth.isLoggedIn(), style.archived); // This path must come before paths with variables
	app.get('/styleset/:stylesetIdPopulated', auth.isLoggedIn(), styleset.open);
	app.post('/style', auth.isLoggedIn(), styleset.load(), style.create);
	app.get('/style/:styleId', auth.isLoggedIn(), style.open);
	app.put('/styleset/:stylesetIdPopulated/update', auth.isLoggedIn(), styleset.update);
	app.put('/style/:styleIdPopulated/update', auth.isLoggedIn(), style.update);
	app.put('/styleset/rearrange', auth.isLoggedIn(), styleset.rearrange);
	app.put('/styleset/:stylesetId/archive', auth.isLoggedIn(), styleset.archive);
	app.put('/styleset/:stylesetId/unarchive', auth.isLoggedIn(), styleset.unarchive);
	app.put('/style/:styleId/archive', auth.isLoggedIn(), style.archive);
	app.put('/style/:styleId/unarchive', auth.isLoggedIn(), style.unarchive);
	app.put('/styleset/:stylesetIdPopulated/project/:projectIdPopulated', auth.isLoggedIn(), project.applyStyleset);
	app.put('/styleset/:stylesetIdPopulated/document/:documentId', auth.isLoggedIn(), document.applyStyleset);
	app.get('/document/:documentIdPopulatedStylesets/stylesets', auth.isLoggedIn(), document.listStylesets);
	app.post('/font', auth.isLoggedIn(), font.create);

	/* Payment */
	app.get('/payment/token', auth.isLoggedIn(), payment.token);
	app.post('/payment/subscription', auth.isLoggedIn(), payment.create_subscription);
	app.delete('/payment/subscription', auth.isLoggedIn(), payment.cancel_subscription);
	app.post('/payment/transaction', auth.isLoggedIn(), payment.transaction);
	app.post('/payment/transaction/styleset/:stylesetId', auth.isLoggedIn(), payment.transaction);

	app.get('/payment/webhook', payment.initWebhook);
	app.post('/payment/webhook', payment.webhook);

	/* API Output */
	app.get('/project/:projectIdPopulatedFull/compile', auth.isLoggedIn(), project.compile);
	app.post('/project/:projectIdPopulated/publish', auth.isLoggedIn(), project.publish);
	app.delete('/project/:projectId/publish', auth.isLoggedIn(), project.unpublish);
	app.get('/project/:projectId/epub', auth.isLoggedIn(), project.downloadEpub);
	app.get('/'+conf.publish.route+'/:projectIdNoAccessCheck/*', project.renderEpubReader);
	app.get('/server/status', server.status);

	// API Parameters
	app.param('projectId', function (req, res, next, id) {
		return project.load(id)(req, res, next);
	});
	app.param('projectIdNoAccessCheck', function (req, res, next, id) {
		return project.loadNoAccessCheck(id)(req, res, next);
	});
	app.param('projectIdNoPremiumCheck', function (req, res, next, id) {
		return project.loadWithoutPremiumCheck(id)(req, res, next);
	});
	app.param('projectIdPopulated', function (req, res, next, id) {
		return project.loadPopulated(id)(req, res, next);
	});
	app.param('projectIdPopulatedFull', function (req, res, next, id) {
		return project.loadPopulatedFull(id)(req, res, next);
	});
	app.param('documentId', function (req, res, next, id) {
		return document.load(id)(req, res, next);
	});
	app.param('documentIdPopulatedStylesets', function (req, res, next, id) {
		return document.loadPopulated(id)(req, res, next);
	});
	app.param('stylesetId', function (req, res, next, id) {
		return styleset.load(id)(req, res, next);
	});
	app.param('stylesetIdPopulated', function (req, res, next, id) {
		return styleset.loadPopulated(id)(req, res, next);
	});
	app.param('styleId', function (req, res, next, id) {
		return style.load(id)(req, res, next);
	});
	app.param('styleIdPopulated', function (req, res, next, id) {
		return style.loadPopulated(id)(req, res, next);
	});
}
