-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
84 lines (68 loc) · 2.43 KB
/
index.js
File metadata and controls
84 lines (68 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
const padInfo = require('ep_etherpad-lite/node/utils/nestedPad'); // @Hossein
const db = require('ep_etherpad-lite/node/db/DB');
const eejs = require('ep_etherpad-lite/node/eejs');
const useragent = require('express-useragent');
const packageJson = require('./package.json');
let userAgent = {};
exports.eejsBlock_styles = (hookName, args, cb) => {
if (!userAgent.isMobile) return cb();
const css = `outterMobile.css?v=${packageJson.version}`;
args.content += `<link
rel="stylesheet"
href="../static/plugins/ep_mobile_view/static/css/${css}"
type="text/css"
/>`;
return cb();
};
exports.clientVars = (hookName, context, callback) => {
const clientVars = {
userAgent: {
...userAgent,
},
};
return callback(clientVars);
};
exports.expressCreateServer = (hookName, args, callback) => {
args.app.use(useragent.express(), (req, res, next) => {
userAgent = req.useragent;
return next();
});
args.app.get('/pluginfw/ep_mobile_view/manifest.json', async (req, res) => {
res.sendFile(`${__dirname}/manifest.json`);
});
args.app.get('/pluginfw/ep_mobile_view/logo/:logoName', async (req, res) => {
const {logoName} = req.params;
res.sendFile(`${__dirname}/static/img/${logoName}`);
});
args.app.get('/pluginfw/ep_mobile_view/screenshot/:screenshot', async (req, res) => {
const {screenshot} = req.params;
res.sendFile(`${__dirname}/static/img/${screenshot}`);
});
args.app.get('/p/:pad*', async (req, res, next) => {
if (/(\/static\/plugins\/(.*))/.test(req.path)) return next();
if (!userAgent.isMobile) return next();
let staticRootAddress = req.path.split('/');
const {padId, padName, padView} = padInfo(req);
staticRootAddress = req.path.split('/')
.filter((x) => x.length)
.map((path) => '../')
.join('');
// @Samir Sayyad Added for social preview
// can be removed when require-kernel is dropped
res.header('Feature-Policy', 'sync-xhr \'self\'');
// @Samir Sayyad Added for social preview
const padTitle = await db.get(`title:${padId}`);
// can be removed when require-kernel is dropped
res.header('Feature-Policy', 'sync-xhr \'self\'');
res.send(eejs.require('ep_mobile_view/static/templates/pad.html', {
meta: {title: (padTitle) ? padTitle : req.params.pad},
padId,
padView,
padName,
staticRootAddress,
req,
userAgent,
}));
});
return callback();
};