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
|
2015-12-31 04:22:35 -05:00
|
|
|
ProjectLocator.findElement {
|
|
|
|
project_id: project_id,
|
|
|
|
element_id: doc_id,
|
|
|
|
type: 'doc'
|
|
|
|
}, (err, doc) ->
|
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 finding doc to index"
|
2015-12-17 06:51:14 -05:00
|
|
|
return res.send 500
|
2016-01-14 09:53:08 -05:00
|
|
|
ReferencesSearchHandler.indexFile project_id, doc_id, (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
|
2016-01-21 12:01:24 -05:00
|
|
|
|
2016-01-22 09:23:59 -05:00
|
|
|
index: (req, res) ->
|
|
|
|
projectId = req.params.Project_id
|
2016-01-21 12:01:24 -05:00
|
|
|
shouldBroadcast = req.body.shouldBroadcast
|
2016-01-22 09:23:59 -05:00
|
|
|
docIds = req.body.docIds
|
|
|
|
if (not docIds instanceof Array) and (docIds != "ALL")
|
|
|
|
logger.err {projectId, docIds}, "docIds is not valid, should be either Array or String 'ALL'"
|
|
|
|
return res.send 400
|
|
|
|
logger.log {projectId, docIds}, "index references for project"
|
|
|
|
ReferencesSearchHandler.index projectId, docIds, (err, data) ->
|
2016-01-21 12:01:24 -05:00
|
|
|
if err
|
2016-01-22 09:23:59 -05:00
|
|
|
logger.err {err, projectId}, "error indexing references"
|
2016-01-21 12:01:24 -05:00
|
|
|
return res.send 500
|
|
|
|
# TODO: optionally broadcast to all connected clients
|
|
|
|
return res.json data
|