mirror of
https://github.com/status-im/universal-links-handler.git
synced 2025-02-24 08:38:18 +00:00
add support for shorter URLs
Signed-off-by: Jakub Sokołowski <jakub@status.im>
This commit is contained in:
parent
042a91e436
commit
bd8b46e4fd
179
routes/index.js
179
routes/index.js
@ -6,7 +6,106 @@ var utils = require('../utils')
|
||||
|
||||
var router = express.Router()
|
||||
|
||||
router.get('/', function (req, res, next) {
|
||||
router.get('/health', (req, res) => {
|
||||
res.send('OK')
|
||||
})
|
||||
|
||||
router.get('/.well-known/assetlinks.json', (req, res) => {
|
||||
res.json(assetLinks)
|
||||
})
|
||||
|
||||
router.get('/.well-known/apple-app-site-association', (req, res) => {
|
||||
res.json(appleSiteAssociation)
|
||||
})
|
||||
|
||||
const genPage = (res, options) => {
|
||||
let opts = {
|
||||
...options,
|
||||
buttonTitle: 'Open in Status',
|
||||
buttonUrl: options.path,
|
||||
}
|
||||
utils.makeQrCodeDataUri(options.path).then(
|
||||
qrUri => res.render('index', { ...opts, qrUri }),
|
||||
error => res.render('index', opts)
|
||||
)
|
||||
}
|
||||
|
||||
/* Helper for full URLs, can specify optional path */
|
||||
const fullUrl = (req, path) => (
|
||||
`${req.protocol}://${req.hostname}${path ? path : req.originalUrl}`
|
||||
)
|
||||
|
||||
/* Website/Dapp */
|
||||
router.get('/b/:url(*)', (req, res) => {
|
||||
let { url } = req.params
|
||||
url = url.replace(/https?:\/\//, '')
|
||||
genPage(res, {
|
||||
title: `Browse to ${url} in Status`,
|
||||
info: `Browse to ${url} in Status`,
|
||||
copyTarget: url,
|
||||
headerName: `<a href="https://${url}">${url}</a>`,
|
||||
path: fullUrl(req, `/b/${url}`),
|
||||
})
|
||||
})
|
||||
|
||||
/* Legacy Website/Dapp */
|
||||
router.get('/browse/:url(*)', (req, res) => {
|
||||
res.redirect(`/b/${req.params.url}`)
|
||||
})
|
||||
|
||||
/* User ENS Name */
|
||||
router.get(/^\/@(.+)$/, (req, res) => {
|
||||
const username = req.params[0]
|
||||
genPage(res, {
|
||||
title: `Join @${username} in Status`,
|
||||
info: `Chat and transact with <span>@${username}</span> in Status.`,
|
||||
copyTarget: username,
|
||||
headerName: `@${username}`,
|
||||
path: fullUrl(req),
|
||||
})
|
||||
})
|
||||
|
||||
/* Legacy User, key or name */
|
||||
router.get('/user/:userId', (req, res) => {
|
||||
const { userId } = req.params
|
||||
if (userId.startsWith('0x04')) {
|
||||
res.redirect(`/${userId}`) /* Chat key */
|
||||
} else {
|
||||
res.redirect(`/@${userId}`) /* ENS name */
|
||||
}
|
||||
})
|
||||
|
||||
/* User Chat Key */
|
||||
router.get(/^\/(0x04[a-f0-9]{128})$/, (req, res) => {
|
||||
const chatKey = req.params[0]
|
||||
chatName = StatusIm.chatKeyToChatName(chatKey)
|
||||
genPage(res, {
|
||||
title: `Join ${chatName} in Status`,
|
||||
info: `Chat and transact with <span>@${chatKey}</span> in Status.`,
|
||||
copyTarget: chatKey,
|
||||
headerName: chatName,
|
||||
path: fullUrl(req),
|
||||
})
|
||||
})
|
||||
|
||||
/* Public Channel */
|
||||
router.get(/^\/([a-z0-9-]+)$/, (req, res) => {
|
||||
const chatName = req.params[0]
|
||||
genPage(res, {
|
||||
title: `Join #${chatName} in Status`,
|
||||
info: `Join public channel <span>#${chatName}</span> on Status.`,
|
||||
headerName: `#${chatName}`,
|
||||
copyTarget: chatName,
|
||||
path: fullUrl(req),
|
||||
})
|
||||
})
|
||||
|
||||
/* Legacy Public Channel */
|
||||
router.get('/chat/public/:chatId', (req, res) => {
|
||||
res.redirect(`/${req.params.chatId}`)
|
||||
})
|
||||
|
||||
router.get('/', (req, res, next) => {
|
||||
if (req.query.redirect) {
|
||||
return next()
|
||||
}
|
||||
@ -22,83 +121,7 @@ router.get('/', function (req, res, next) {
|
||||
return res.redirect("https://testflight.apple.com/join/J8EuJmey")
|
||||
}
|
||||
|
||||
return res.redirect("https://status.im")
|
||||
})
|
||||
|
||||
router.get('/health', function(req, res) {
|
||||
res.send('OK')
|
||||
})
|
||||
|
||||
router.get('/.well-known/assetlinks.json', function(req, res) {
|
||||
res.json(assetLinks)
|
||||
})
|
||||
|
||||
router.get('/.well-known/apple-app-site-association', function(req, res) {
|
||||
res.json(appleSiteAssociation)
|
||||
})
|
||||
|
||||
router.get('/chat/:chatType/:chatId', function(req, res, next) {
|
||||
const { chatId, chatType } = req.params
|
||||
const statusUri = `status-im://chat/${chatType}/${chatId}`
|
||||
const options = {
|
||||
title: `Join ${chatType} channel #${chatId} on Status`,
|
||||
info: `Join public channel <span>#${chatId}</span> on Status.`,
|
||||
headerName: `#${chatId}`,
|
||||
copyTarget: chatId,
|
||||
path: req.originalUrl,
|
||||
}
|
||||
/* Make button open chat if on Android */
|
||||
if (utils.isAndroid(req.headers['user-agent'])) {
|
||||
options.buttonTitle = 'Open in Status'
|
||||
options.buttonUrl = statusUri
|
||||
}
|
||||
utils.makeQrCodeDataUri(statusUri).then(
|
||||
qrUri => res.render('index', { ...options, qrUri }),
|
||||
error => res.render('index', options)
|
||||
)
|
||||
})
|
||||
|
||||
router.get('/user/:userId', function(req, res, next) {
|
||||
const { userId } = req.params
|
||||
const statusUri = `status-im://user/${userId}`
|
||||
/* chat keys can be resolved to chat names */
|
||||
let chatName = userId
|
||||
if (utils.isChatKey(userId)) {
|
||||
chatName = StatusIm.chatKeyToChatName(userId)
|
||||
}
|
||||
const options = {
|
||||
title: `Join ${chatName} in Status`,
|
||||
info: `Chat and transact with <span>${userId}</span> in Status.`,
|
||||
copyTarget: userId,
|
||||
headerName: chatName,
|
||||
path: req.originalUrl,
|
||||
}
|
||||
/* Make button open user profile if on Android */
|
||||
if (utils.isAndroid(req.headers['user-agent'])) {
|
||||
options.buttonTitle = 'Open in Status'
|
||||
options.buttonUrl = statusUri
|
||||
}
|
||||
utils.makeQrCodeDataUri(statusUri).then(
|
||||
qrUri => res.render('index', { ...options, qrUri }),
|
||||
error => res.render('index', options)
|
||||
)
|
||||
})
|
||||
|
||||
router.get('/browse/:url(*)', function(req, res, next) {
|
||||
let { url } = req.params
|
||||
url = url.replace(/https?:\/\//, '')
|
||||
const statusUri = `status-im://browse/${url}`
|
||||
const options = {
|
||||
title: `Browse to ${url} in Status`,
|
||||
info: `Browse to ${url} in Status`,
|
||||
copyTarget: url,
|
||||
headerName: `<a href="https://${url}">${url}</a>`,
|
||||
path: req.originalUrl,
|
||||
}
|
||||
utils.makeQrCodeDataUri(statusUri).then(
|
||||
qrUri => res.render('index', { ...options, qrUri }),
|
||||
error => res.render('index', options),
|
||||
)
|
||||
return res.redirect("https://status.im/get/")
|
||||
})
|
||||
|
||||
module.exports = router
|
||||
|
Loading…
x
Reference in New Issue
Block a user