share.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. var express = require('express');
  2. var router = express.Router();
  3. const utils = require('../../libs/utils');
  4. const config = require('../../config/app');
  5. // deeplink share 专属页路由
  6. router.get('/:id', function (req, res, next) {
  7. (async function () {
  8. let id = req.params.id;
  9. utils.validators.validateId(id);
  10. let host = config.cdnHost ?? config.resHost;
  11. let imageUrl = `${host}/thumbs/coloring-page/work/480/${id}.webp`;
  12. let applink = `https://art.pcoloring.com${req.originalUrl}`;
  13. let downlink = `https://pcoloring.com/anc/`;
  14. const userAgent = req.headers['user-agent'];
  15. console.log('User-Agent:', userAgent);
  16. if (userAgent) {
  17. const ua = userAgent.toLowerCase();
  18. if (ua.includes('iphone') || ua.includes('ipad') || ua.includes('ipod')) {
  19. downlink = 'itms-apps://itunes.apple.com/app/id1575480118?action=write-review';
  20. } else if (ua.includes('android')) {
  21. downlink = 'https://play.google.com/store/apps/details?id=com.pcoloring.art.puzzle.color.by.number&pcampaignid=web_share';
  22. }
  23. }
  24. let data = {
  25. id,
  26. imageUrl,
  27. applink,
  28. downlink,
  29. }
  30. // 渲染EJS模板到内存中
  31. res.render('v2/share', data, async (err, html) => {
  32. if (err) {
  33. // 如果渲染出错,调用next()传递错误
  34. return next(err);
  35. }
  36. res.send(html);
  37. });
  38. })().catch(next);
  39. });
  40. module.exports = router;