Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Views: 39534
1
fs = require('fs')
2
winston = require('winston')
3
misc = require('smc-util/misc')
4
kucalc = require('./kucalc')
5
6
exports.secret_token_filename = ->
7
if kucalc.IN_KUCALC
8
return process.env.COCALC_SECRET_TOKEN
9
else
10
return "#{process.env.SMC}/secret_token"
11
12
_secret_token = undefined
13
exports.secret_token = -> # doing sync is ok since only happens rarely at startup and is quick
14
return _secret_token ?= fs.readFileSync(exports.secret_token_filename())
15
16
# We make it an error for a client to try to edit a file larger than MAX_FILE_SIZE.
17
# I decided on this, because attempts to open a much larger file leads
18
# to disaster. Opening a 10MB file works but is a just a little slow.
19
MAX_FILE_SIZE = 10000000 # 10MB
20
exports.check_file_size = (size) ->
21
if size? and size > MAX_FILE_SIZE
22
e = "Attempt to open large file of size #{Math.round(size/1000000)}MB; the maximum allowed size is #{Math.round(MAX_FILE_SIZE/1000000)}MB. Use vim, emacs, or pico from a terminal instead."
23
winston.debug(e)
24
return e
25
26
exports.json = (out) ->
27
misc.trunc(misc.to_json(out),500)
28