mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-24 03:33:27 +00:00
experimental: update references index from fronted.
This commit is contained in:
parent
1ad27bb6ed
commit
249dd638ec
3 changed files with 72 additions and 8 deletions
|
@ -0,0 +1,35 @@
|
|||
logger = require('logger-sharelatex')
|
||||
ReferencesSearchHandler = require('./ReferencesSearchHandler')
|
||||
ProjectLocator = require("../Project/ProjectLocator")
|
||||
settings = require('settings-sharelatex')
|
||||
U = require('underscore')
|
||||
|
||||
|
||||
module.exports = ReferencesSearchController =
|
||||
|
||||
indexFile: (req, res) ->
|
||||
project_id = req.params.Project_id
|
||||
user_id = req.session.user._id
|
||||
doc_id = req.body.docId
|
||||
logger.log {project_id, user_id, doc_id}, "indexing references"
|
||||
|
||||
if !doc_id
|
||||
logger.log project_id: project_id, user_id: user_id, "no fileUrl supplied"
|
||||
return res.send 400
|
||||
ProjectLocator.findElement {project_id: project_id, element_id: doc_id, type: 'doc'}, (err, doc) ->
|
||||
if err?
|
||||
logger.err {err, project_id, user_id, doc_id}, "error finding element for downloading file"
|
||||
return res.send 500
|
||||
doc_url = ReferencesSearchController._buildDocUrl project_id, doc_id
|
||||
console.log ">>"
|
||||
console.log doc, doc_url
|
||||
console.log "<<"
|
||||
ReferencesSearchHandler.indexFile user_id, doc_url, (err) ->
|
||||
if err
|
||||
logger.err {err, project_id, user_id, doc_id}, "error indexing references file"
|
||||
return res.send 500
|
||||
|
||||
res.send 200
|
||||
|
||||
_buildDocUrl: (project_id, doc_id) ->
|
||||
"#{settings.apis.web.url}/project/#{project_id}/doc/#{doc_id}"
|
|
@ -0,0 +1,26 @@
|
|||
logger = require("logger-sharelatex")
|
||||
request = require("request")
|
||||
settings = require("settings-sharelatex")
|
||||
|
||||
oneMinInMs = 60 * 1000
|
||||
fiveMinsInMs = oneMinInMs * 5
|
||||
|
||||
|
||||
module.exports = ReferencesSearchHandler =
|
||||
|
||||
indexFile: (user_id, file_url, callback = (err)->) ->
|
||||
logger.log {user_id, file_url}, "sending index request to references api"
|
||||
url = "#{settings.apis.references.url}/user/#{user_id}"
|
||||
request.post {
|
||||
url: url
|
||||
json:
|
||||
referencesUrl: file_url
|
||||
}, (err, res, result) ->
|
||||
if err
|
||||
return callback(err)
|
||||
if 200 <= res.statusCode < 300
|
||||
return callback(null)
|
||||
else
|
||||
err = new Error("references api responded with non-success code: #{res.statusCode}")
|
||||
logger.log {err, user_id, file_url}, "error updating references"
|
||||
return callback(err)
|
|
@ -37,6 +37,7 @@ RateLimiterMiddlewear = require('./Features/Security/RateLimiterMiddlewear')
|
|||
RealTimeProxyRouter = require('./Features/RealTimeProxy/RealTimeProxyRouter')
|
||||
InactiveProjectController = require("./Features/InactiveData/InactiveProjectController")
|
||||
ContactRouter = require("./Features/Contacts/ContactRouter")
|
||||
ReferencesSearchController = require('./Features/ReferencesSearch/ReferencesSearchController')
|
||||
|
||||
logger = require("logger-sharelatex")
|
||||
_ = require("underscore")
|
||||
|
@ -46,7 +47,7 @@ module.exports = class Router
|
|||
if !Settings.allowPublicAccess
|
||||
webRouter.all '*', AuthenticationController.requireGlobalLogin
|
||||
|
||||
|
||||
|
||||
webRouter.get '/login', UserPagesController.loginPage
|
||||
AuthenticationController.addEndpointToLoginWhitelist '/login'
|
||||
|
||||
|
@ -67,18 +68,18 @@ module.exports = class Router
|
|||
StaticPagesRouter.apply(webRouter, apiRouter)
|
||||
RealTimeProxyRouter.apply(webRouter, apiRouter)
|
||||
ContactRouter.apply(webRouter, apiRouter)
|
||||
|
||||
|
||||
Modules.applyRouter(webRouter, apiRouter)
|
||||
|
||||
|
||||
if Settings.enableSubscriptions
|
||||
webRouter.get '/user/bonus', AuthenticationController.requireLogin(), ReferalMiddleware.getUserReferalId, ReferalController.bonus
|
||||
|
||||
|
||||
webRouter.get '/blog', BlogController.getIndexPage
|
||||
webRouter.get '/blog/*', BlogController.getPage
|
||||
|
||||
|
||||
webRouter.get '/user/activate', UserPagesController.activateAccountPage
|
||||
|
||||
|
||||
webRouter.get '/user/settings', AuthenticationController.requireLogin(), UserPagesController.settingsPage
|
||||
webRouter.post '/user/settings', AuthenticationController.requireLogin(), UserController.updateUserSettings
|
||||
webRouter.post '/user/password/update', AuthenticationController.requireLogin(), UserController.changePassword
|
||||
|
@ -158,7 +159,7 @@ module.exports = class Router
|
|||
|
||||
apiRouter.post '/user/:user_id/update/*', AuthenticationController.httpAuth, TpdsController.mergeUpdate
|
||||
apiRouter.delete '/user/:user_id/update/*', AuthenticationController.httpAuth, TpdsController.deleteUpdate
|
||||
|
||||
|
||||
apiRouter.post '/project/:project_id/contents/*', AuthenticationController.httpAuth, TpdsController.updateProjectContents
|
||||
apiRouter.delete '/project/:project_id/contents/*', AuthenticationController.httpAuth, TpdsController.deleteProjectContents
|
||||
|
||||
|
@ -167,9 +168,11 @@ module.exports = class Router
|
|||
|
||||
webRouter.get "/project/:Project_id/messages", SecurityManager.requestCanAccessProject, ChatController.getMessages
|
||||
webRouter.post "/project/:Project_id/messages", SecurityManager.requestCanAccessProject, ChatController.sendMessage
|
||||
|
||||
|
||||
webRouter.get /learn(\/.*)?/, WikiController.getPage
|
||||
|
||||
webRouter.post "/project/:Project_id/references", SecurityManager.requestCanAccessProject, ReferencesSearchController.indexFile
|
||||
|
||||
#Admin Stuff
|
||||
webRouter.get '/admin', SecurityManager.requestIsAdmin, AdminController.index
|
||||
webRouter.get '/admin/user', SecurityManager.requestIsAdmin, (req, res)-> res.redirect("/admin/register") #this gets removed by admin-panel addon
|
||||
|
@ -188,7 +191,7 @@ module.exports = class Router
|
|||
|
||||
apiRouter.get '/status', (req,res)->
|
||||
res.send("websharelatex is up")
|
||||
|
||||
|
||||
|
||||
webRouter.get '/health_check', HealthCheckController.check
|
||||
webRouter.get '/health_check/redis', HealthCheckController.checkRedis
|
||||
|
|
Loading…
Reference in a new issue