2018-06-28 06:47:06 +00:00
|
|
|
var express = require('express');
|
2020-02-10 20:44:04 +00:00
|
|
|
var StatusIm = require('js-status-chat-name')
|
2018-06-28 06:47:06 +00:00
|
|
|
var assetLinks = require('../resources/assetlinks.json');
|
2018-06-28 20:11:45 +00:00
|
|
|
var appleSiteAssociation = require('../resources/apple-app-site-association.json');
|
2020-02-10 20:44:04 +00:00
|
|
|
var utils = require('../utils');
|
2018-10-05 05:31:10 +00:00
|
|
|
|
|
|
|
var router = express.Router();
|
2018-06-28 06:47:06 +00:00
|
|
|
|
2018-07-02 18:48:58 +00:00
|
|
|
router.get('/', function (req, res, next) {
|
2018-07-02 13:07:23 +00:00
|
|
|
if (req.query.redirect) {
|
2018-07-03 06:26:25 +00:00
|
|
|
return next();
|
2018-07-02 13:07:23 +00:00
|
|
|
}
|
|
|
|
|
2018-07-03 05:56:55 +00:00
|
|
|
res.header('Cache-Control', 'private, no-cache, no-store, must-revalidate');
|
|
|
|
res.header('Expires', '-1');
|
|
|
|
res.header('Pragma', 'no-cache');
|
|
|
|
|
2020-02-10 20:44:04 +00:00
|
|
|
var userAgent = req.headers['user-agent'];
|
|
|
|
if (utils.isAndroid(userAgent)) {
|
2018-07-03 06:26:25 +00:00
|
|
|
return res.redirect("https://play.google.com/store/apps/details?id=im.status.ethereum");
|
2020-02-10 20:44:04 +00:00
|
|
|
} else if (utils.isIOS(userAgent)) {
|
2018-09-26 17:55:22 +00:00
|
|
|
return res.redirect("https://testflight.apple.com/join/J8EuJmey");
|
2018-07-02 13:07:23 +00:00
|
|
|
}
|
|
|
|
|
2018-07-03 06:26:25 +00:00
|
|
|
return res.redirect("https://status.im");
|
|
|
|
});
|
2018-07-02 13:07:23 +00:00
|
|
|
|
2018-06-28 11:15:04 +00:00
|
|
|
router.get('/health', function(req, res) {
|
|
|
|
res.send('OK');
|
|
|
|
});
|
2018-06-28 06:47:06 +00:00
|
|
|
|
|
|
|
router.get('/.well-known/assetlinks.json', function(req, res) {
|
|
|
|
res.json(assetLinks);
|
|
|
|
});
|
|
|
|
|
2018-06-28 20:11:45 +00:00
|
|
|
router.get('/.well-known/apple-app-site-association', function(req, res) {
|
|
|
|
res.json(appleSiteAssociation);
|
|
|
|
});
|
|
|
|
|
2018-07-02 18:48:58 +00:00
|
|
|
router.get('/chat/:chatType/:chatId', function(req, res, next) {
|
2018-07-03 06:26:25 +00:00
|
|
|
const { chatId, chatType } = req.params;
|
2020-02-12 19:27:25 +00:00
|
|
|
chatName = `#${chatId}`;
|
|
|
|
const options = {
|
|
|
|
title: `Join ${chatType} channel #${chatId} on Status`,
|
|
|
|
info: `Join public channel <span>#${chatId}</span> on Status.`,
|
2020-02-10 18:17:55 +00:00
|
|
|
path: req.originalUrl,
|
2020-02-10 20:44:04 +00:00
|
|
|
chatId: chatId,
|
2020-02-12 19:27:25 +00:00
|
|
|
chatName: chatName,
|
|
|
|
};
|
|
|
|
utils.makeQrCodeDataUri(chatName).then(
|
|
|
|
qrCodeDataUri => res.render('index', { ...options, qrCodeDataUri }),
|
|
|
|
error => res.render('index', options)
|
|
|
|
);
|
2018-06-28 06:47:06 +00:00
|
|
|
});
|
|
|
|
|
2018-07-02 18:48:58 +00:00
|
|
|
router.get('/user/:userId', function(req, res, next) {
|
2018-10-05 05:31:10 +00:00
|
|
|
const { userId } = req.params;
|
2020-02-10 20:44:04 +00:00
|
|
|
chatName = userId
|
|
|
|
/* chat keys can be resolved to chat names */
|
|
|
|
if (utils.isChatKey(userId)) {
|
|
|
|
chatName = StatusIm.chatKeyToChatName(userId)
|
|
|
|
}
|
2018-10-05 05:31:10 +00:00
|
|
|
const options = {
|
2020-02-10 20:44:04 +00:00
|
|
|
title: `Join ${chatName} in Status`,
|
|
|
|
info: `Chat and transact with <span>${userId}</span> in Status.`,
|
2018-10-05 05:31:10 +00:00
|
|
|
path: req.originalUrl,
|
2020-02-10 20:44:04 +00:00
|
|
|
chatId: userId,
|
|
|
|
chatName: chatName,
|
2018-10-05 05:31:10 +00:00
|
|
|
};
|
2020-02-10 20:44:04 +00:00
|
|
|
utils.makeQrCodeDataUri(userId).then(
|
2018-10-05 05:31:10 +00:00
|
|
|
qrCodeDataUri => res.render('index', { ...options, qrCodeDataUri }),
|
|
|
|
error => res.render('index', options)
|
|
|
|
);
|
2018-06-28 07:27:15 +00:00
|
|
|
});
|
|
|
|
|
2018-12-01 18:56:51 +00:00
|
|
|
router.get('/extension/:extensionEndpoint', function(req, res, next) {
|
|
|
|
const { extensionEndpoint } = req.params;
|
|
|
|
const options = {
|
|
|
|
title: `Open extension ${extensionEndpoint} in Status`,
|
2020-02-10 20:44:04 +00:00
|
|
|
info: `Open the <span>${extensionEndpoint}</span> extension in Status.`,
|
2018-12-01 18:56:51 +00:00
|
|
|
path: req.originalUrl,
|
2020-02-10 20:44:04 +00:00
|
|
|
chatId: extensionEndpoint,
|
|
|
|
chatName: extensionEndpoint,
|
2018-12-01 18:56:51 +00:00
|
|
|
};
|
2020-02-10 20:44:04 +00:00
|
|
|
utils.makeQrCodeDataUri('https://join.status.im/extension/' + extensionEndpoint).then(
|
2018-12-01 18:56:51 +00:00
|
|
|
qrCodeDataUri => res.render('index', { ...options, qrCodeDataUri }),
|
|
|
|
error => res.render('index', options)
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2018-07-05 09:28:59 +00:00
|
|
|
router.get('/browse/:url(*)', function(req, res, next) {
|
2018-06-28 07:27:15 +00:00
|
|
|
res.render('index', {
|
2018-07-03 06:26:25 +00:00
|
|
|
title: `Browse to ${req.params.url} in Status`,
|
2020-02-10 18:17:55 +00:00
|
|
|
path: req.originalUrl,
|
|
|
|
id: `${req.params.url}`
|
2018-06-28 06:47:06 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = router;
|