2015-12-17 06:51:14 -05:00
|
|
|
logger = require('logger-sharelatex')
|
|
|
|
ReferencesSearchHandler = require('./ReferencesSearchHandler')
|
|
|
|
ProjectLocator = require("../Project/ProjectLocator")
|
|
|
|
settings = require('settings-sharelatex')
|
|
|
|
|
|
|
|
module.exports = ReferencesSearchController =
|
|
|
|
|
|
|
|
indexFile: (req, res) ->
|
|
|
|
project_id = req.params.Project_id
|
|
|
|
doc_id = req.body.docId
|
2015-12-18 09:57:36 -05:00
|
|
|
logger.log {project_id, doc_id}, "indexing references"
|
2015-12-17 06:51:14 -05:00
|
|
|
|
|
|
|
if !doc_id
|
2015-12-18 09:57:36 -05:00
|
|
|
logger.log project_id: project_id, "no fileUrl supplied"
|
2015-12-17 06:51:14 -05:00
|
|
|
return res.send 400
|
|
|
|
ProjectLocator.findElement {project_id: project_id, element_id: doc_id, type: 'doc'}, (err, doc) ->
|
|
|
|
if err?
|
2015-12-18 09:57:36 -05:00
|
|
|
logger.err {err, project_id, doc_id}, "error finding doc to index"
|
2015-12-17 06:51:14 -05:00
|
|
|
return res.send 500
|
|
|
|
doc_url = ReferencesSearchController._buildDocUrl project_id, doc_id
|
2015-12-18 09:57:36 -05:00
|
|
|
ReferencesSearchHandler.indexFile project_id, doc_url, (err) ->
|
2015-12-17 06:51:14 -05:00
|
|
|
if err
|
2015-12-18 09:57:36 -05:00
|
|
|
logger.err {err, project_id, doc_id}, "error indexing references file"
|
2015-12-17 06:51:14 -05:00
|
|
|
return res.send 500
|
|
|
|
|
|
|
|
res.send 200
|
|
|
|
|
2015-12-18 11:00:24 -05:00
|
|
|
getKeys: (req, res) ->
|
|
|
|
project_id = req.params.Project_id
|
|
|
|
logger.log {project_id}, "getting project references keys"
|
|
|
|
ReferencesSearchHandler.getKeys project_id, (err, data) ->
|
|
|
|
if err
|
|
|
|
logger.err {err, project_id}, "error getting references keys"
|
|
|
|
return res.send 500
|
|
|
|
return res.json data
|
|
|
|
|
2015-12-17 06:51:14 -05:00
|
|
|
_buildDocUrl: (project_id, doc_id) ->
|
|
|
|
"#{settings.apis.web.url}/project/#{project_id}/doc/#{doc_id}"
|