search_view.js 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612
  1. const { form, button, div, h2, p, section, input, select, option, img, audio: audioHyperaxe, video: videoHyperaxe, table, hr, hd, br, td, tr, th, a, span } = require("../server/node_modules/hyperaxe");
  2. const { template, i18n } = require('./main_views');
  3. const moment = require("../server/node_modules/moment");
  4. const { renderTextWithStyles } = require('../backend/renderTextWithStyles');
  5. const { renderUrl } = require('../backend/renderUrl');
  6. const { sanitizeHtml } = require('../backend/sanitizeHtml');
  7. const decodeMaybe = (s) => {
  8. try { return decodeURIComponent(String(s || '')); } catch { return String(s || ''); }
  9. };
  10. const rewriteHashtagLinks = (html) => {
  11. const s = String(html || '');
  12. return s.replace(/href=(["'])(?:https?:\/\/[^"']+)?\/hashtag\/([^"'?#]+)([^"']*)\1/g, (m, q, tag, rest) => {
  13. const t = decodeMaybe(tag).replace(/^#/, '').trim().toLowerCase();
  14. const href = `/search?query=%23${encodeURIComponent(t)}`;
  15. return `href=${q}${href}${q}`;
  16. });
  17. };
  18. const searchView = ({ messages = [], blobs = {}, query = "", type = "", types = [], hashtag = null, results = {}, resultCount = "10" }) => {
  19. const searchInput = input({
  20. name: "query",
  21. required: false,
  22. type: "search",
  23. value: query,
  24. placeholder: i18n.searchPlaceholder
  25. });
  26. searchInput.setAttribute("minlength", 3);
  27. const contentTypes = [
  28. "post", "about", "curriculum", "tribe", "market", "transfer", "feed", "votes",
  29. "report", "task", "event", "bookmark", "image", "audio", "video", "document",
  30. "bankWallet", "bankClaim", "project", "job", "forum", "vote", "contact", "pub", "map", "shop", "shopProduct", "chat", "pad", "all"
  31. ];
  32. const filterSelect = select(
  33. {
  34. id: "search-type",
  35. name: "type",
  36. class: "input-select",
  37. style: "position:relative; z-index:10;"
  38. },
  39. contentTypes.map(type =>
  40. option({
  41. value: type === 'all' ? "" : type,
  42. selected: (types.length === 0 && type === 'all') || types.includes(type)
  43. }, i18n[type + "Label"] || type.toUpperCase())
  44. )
  45. );
  46. const resultsPerPageSelect = select(
  47. {
  48. id: "results-per-page",
  49. name: "resultsPerPage",
  50. class: "input-select",
  51. style: "position:relative; z-index:10;margin-left:10px;"
  52. },
  53. option({ value: "100", selected: resultCount === "100" }, "100"),
  54. option({ value: "50", selected: resultCount === "50" }, "50"),
  55. option({ value: "10", selected: resultCount === "10" }, "10"),
  56. option({ value: "all", selected: resultCount === "all" }, i18n.allTypesLabel)
  57. );
  58. const getViewDetailsActionForSearch = (type, contentId, content) => {
  59. switch (type) {
  60. case 'votes': return `/votes/${encodeURIComponent(contentId)}`;
  61. case 'transfer': return `/transfers/${encodeURIComponent(contentId)}`;
  62. case 'tribe': return `/tribe/${encodeURIComponent(contentId)}`;
  63. case 'curriculum': return `/inhabitant/${encodeURIComponent(contentId)}`;
  64. case 'image': return `/images/${encodeURIComponent(contentId)}`;
  65. case 'audio': return `/audios/${encodeURIComponent(contentId)}`;
  66. case 'video': return `/videos/${encodeURIComponent(contentId)}`;
  67. case 'document': return `/documents/${encodeURIComponent(contentId)}`;
  68. case 'bookmark': return `/bookmarks/${encodeURIComponent(contentId)}`;
  69. case 'event': return `/events/${encodeURIComponent(contentId)}`;
  70. case 'task': return `/tasks/${encodeURIComponent(contentId)}`;
  71. case 'post': return `/thread/${encodeURIComponent(contentId)}#${encodeURIComponent(contentId)}`;
  72. case 'market': return `/market/${encodeURIComponent(contentId)}`;
  73. case 'report': return `/reports/${encodeURIComponent(contentId)}`;
  74. case 'project': return `/projects/${encodeURIComponent(contentId)}`;
  75. case 'job': return `/jobs/${encodeURIComponent(contentId)}`;
  76. case 'forum': return `/forum/${encodeURIComponent(contentId)}`;
  77. case 'vote': return content && content.vote && content.vote.link ? `/thread/${encodeURIComponent(content.vote.link)}#${encodeURIComponent(content.vote.link)}` : '#';
  78. case 'contact': return content && content.contact ? `/author/${encodeURIComponent(content.contact)}` : '#';
  79. case 'pub': return '#';
  80. case 'bankWallet': return `/banking`;
  81. case 'bankClaim': return `/banking`;
  82. case 'map': return `/maps/${encodeURIComponent(contentId)}`;
  83. case 'shop': return `/shops/${encodeURIComponent(contentId)}`;
  84. case 'shopProduct': return `/shops/product/${encodeURIComponent(contentId)}`;
  85. case 'chat': return `/chats/${encodeURIComponent(contentId)}`;
  86. case 'pad': return `/pads/${encodeURIComponent(contentId)}`;
  87. case 'gameScore': return content && content.game ? `/games/${encodeURIComponent(content.game)}` : '/games';
  88. default: return '#';
  89. }
  90. };
  91. let hasDocument = false;
  92. const blobImg = (value) => {
  93. if (!value) return null;
  94. const s = String(value).trim().replace(/&/g, '&');
  95. const m = s.match(/!\[[^\]]*\]\(\s*(&[^)\s]+\.sha256)\s*\)/);
  96. const src = m ? m[1] : s;
  97. return src.startsWith('&') ? img({ src: `/blob/${encodeURIComponent(src)}`, class: 'search-result-image' }) : null;
  98. };
  99. const renderContentHtml = (content) => {
  100. switch (content.type) {
  101. case 'post':
  102. return div({ class: 'search-post' },
  103. content.contentWarning ? h2({ class: 'card-field' }, span({ class: 'card-value' }, content.contentWarning)) : null,
  104. content.text ? div({ class: 'card-field' }, span({ class: 'card-value', innerHTML: sanitizeHtml(content.text) })) : null
  105. );
  106. case 'about':
  107. return div({ class: 'search-about' },
  108. content.name ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.name + ':'), span({ class: 'card-value' }, content.name)) : null,
  109. content.description ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.description + ':'), span({ class: 'card-value' }, content.description)) : null,
  110. content.image ? img({ src: `/image/64/${encodeURIComponent(content.image)}` }) : null
  111. );
  112. case 'feed': {
  113. const rawText = typeof content.text === 'string' ? content.text.trim() : '';
  114. const htmlText = rawText ? rewriteHashtagLinks(renderTextWithStyles(rawText)) : '';
  115. const refeedsNum = Number(content.refeeds || 0) || 0;
  116. return div({ class: 'search-feed' },
  117. rawText ? div({ class: 'card-field' }, span({ class: 'card-value', innerHTML: sanitizeHtml(htmlText) })) : null,
  118. refeedsNum > 0
  119. ? h2({ class: 'card-field' },
  120. span({ class: 'card-label' }, i18n.tribeFeedRefeeds + ':'),
  121. span({ class: 'card-value' }, String(refeedsNum))
  122. )
  123. : null
  124. );
  125. }
  126. case 'event': {
  127. const rawEvDesc = content.description || '';
  128. const blobInEvDesc = rawEvDesc.match(/!\[[^\]]*\]\((&[^)\s]+\.sha256)\)/)?.[1] || null;
  129. const cleanEvDesc = rawEvDesc.replace(/!\[[^\]]*\]\(&[^)]+\.sha256\)/g, '').trim();
  130. return div({ class: 'search-event' },
  131. content.title ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.eventTitleLabel + ':'), span({ class: 'card-value' }, content.title)) : null,
  132. cleanEvDesc ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.searchDescription + ':'), span({ class: 'card-value' }, cleanEvDesc)) : null,
  133. blobImg(content.image || blobInEvDesc),
  134. content.date ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.eventDate + ':'), span({ class: 'card-value' }, new Date(content.date).toLocaleString())) : null,
  135. content.location ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.eventLocation + ':'), span({ class: 'card-value' }, content.location)) : null,
  136. content.isPublic ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.eventPrivacyLabel + ':'), span({ class: 'card-value' }, content.isPublic)) : null,
  137. content.status ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.eventStatus + ':'), span({ class: 'card-value' }, content.status)) : null,
  138. content.eventUrl ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.eventUrlLabel + ':'), span({ class: 'card-value' }, a({ href: content.eventUrl, target: '_blank' }, content.eventUrl))) : null,
  139. content.price ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.eventPrice + ':'), span({ class: 'card-value' }, content.price)) : null,
  140. content.tags && content.tags.length
  141. ? div({ class: 'card-tags' }, content.tags.map(tag =>
  142. a({ href: `/search?query=%23${encodeURIComponent(tag)}`, class: 'tag-link' }, `#${tag}`)
  143. ))
  144. : null
  145. );
  146. }
  147. case 'votes':
  148. const votesList = content.votes && typeof content.votes === 'object'
  149. ? Object.entries(content.votes).map(([option, count]) => ({ option, count }))
  150. : [];
  151. return div({ class: 'search-vote' },
  152. br(),
  153. content.question ? div({ class: 'card-field' },
  154. span({ class: 'card-label' }, i18n.voteQuestionLabel + ':' ),
  155. span({ class: 'card-value' }, content.question)
  156. ) : null,
  157. content.status ? div({ class: 'card-field' },
  158. span({ class: 'card-label' }, i18n.voteStatus + ':' ),
  159. span({ class: 'card-value' }, content.status)
  160. ) : null,
  161. content.deadline ? div({ class: 'card-field' },
  162. span({ class: 'card-label' }, i18n.voteDeadline + ':' ),
  163. span({ class: 'card-value' }, content.deadline ? new Date(content.deadline).toLocaleString() : '')
  164. ) : null,
  165. div({ class: 'card-field' },
  166. span({ class: 'card-label' }, i18n.voteTotalVotes + ':' ),
  167. span({ class: 'card-value' }, content.totalVotes !== undefined ? content.totalVotes : '0')
  168. ),
  169. br(),
  170. votesList.length > 0 ? div({ class: 'card-votes' },
  171. table(
  172. tr(...votesList.map(({ option }) => th(i18n[option] || option))),
  173. tr(...votesList.map(({ count }) => td(count)))
  174. )
  175. ) : null
  176. );
  177. case 'tribe':
  178. return div({ class: 'search-tribe' },
  179. content.title ? h2(content.title) : null,
  180. (() => { const s = String(content.image || '').trim().replace(/&/g, '&'); const m = s.match(/!\[[^\]]*\]\(\s*(&[^)\s]+\.sha256)\s*\)/); const src = m ? m[1] : s; return src.startsWith('&') ? img({ src: `/blob/${encodeURIComponent(src)}`, class: 'feed-image' }) : img({ src: '/assets/images/default-tribe.png', class: 'feed-image' }); })(),
  181. br(),
  182. content.description ? content.description : null,
  183. br(),br(),
  184. div({ style: 'display:flex; gap:.6em; flex-wrap:wrap;' },
  185. content.location ? p({ style: 'color:#9aa3b2;' }, `${i18n.tribeLocationLabel.toUpperCase()}: `, ...renderUrl(content.location)) : null,
  186. p({ style: 'color:#9aa3b2;' }, `${i18n.tribeIsAnonymousLabel}: ${content.isAnonymous ? i18n.tribePrivate : i18n.tribePublic}`),
  187. content.inviteMode ? p({ style: 'color:#9aa3b2;' }, `${i18n.tribeModeLabel}: ${content.inviteMode.toUpperCase()}`) : null,
  188. p({ style: 'color:#9aa3b2;' }, `${i18n.tribeLARPLabel}: ${content.isLARP ? i18n.tribeYes : i18n.tribeNo}`)
  189. ),
  190. Array.isArray(content.members)
  191. ? div({},
  192. div({ class: 'card-field' },
  193. h2(`${i18n.tribeMembersCount}: ${content.members.length}`),
  194. )
  195. )
  196. : null,
  197. content.tags && content.tags.length
  198. ? div({ class: 'card-tags' }, content.tags.map(tag =>
  199. a({ href: `/search?query=%23${encodeURIComponent(tag)}`, class: 'tag-link' }, `#${tag}`)
  200. ))
  201. : null
  202. );
  203. case 'audio':
  204. return content.url ? div({ class: 'search-audio' },
  205. content.title ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.audioTitleLabel + ':'), span({ class: 'card-value' }, content.title)) : null,
  206. content.description ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.audioDescriptionLabel + ':'), span({ class: 'card-value' }, content.description)) : null,
  207. br(),
  208. audioHyperaxe({ controls: true, src: `/blob/${encodeURIComponent(content.url)}`, type: content.mimeType, preload: 'metadata' }),
  209. br(),
  210. content.tags && content.tags.length
  211. ? div({ class: 'card-tags' }, content.tags.map(tag =>
  212. a({ href: `/search?query=%23${encodeURIComponent(tag)}`, class: 'tag-link' }, `#${tag}`)
  213. ))
  214. : null
  215. ) : null;
  216. case 'image':
  217. return content.url ? div({ class: 'search-image' },
  218. content.title ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.imageTitleLabel + ':'), span({ class: 'card-value' }, content.title)) : null,
  219. content.description ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.imageDescriptionLabel + ':'), span({ class: 'card-value' }, content.description)) : null,
  220. content.meme ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.trendingCategory + ':'), span({ class: 'card-value' }, i18n.meme)) : null,
  221. br(),
  222. img({ src: `/blob/${encodeURIComponent(content.url)}` }),
  223. br(),
  224. content.tags && content.tags.length
  225. ? div({ class: 'card-tags' }, content.tags.map(tag =>
  226. a({ href: `/search?query=%23${encodeURIComponent(tag)}`, class: 'tag-link' }, `#${tag}`)
  227. ))
  228. : null
  229. ) : null;
  230. case 'video':
  231. return content.url ? div({ class: 'search-video' },
  232. content.title ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.videoTitleLabel + ':'), span({ class: 'card-value' }, content.title)) : null,
  233. content.description ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.videoDescriptionLabel + ':'), span({ class: 'card-value' }, content.description)) : null,
  234. br(),
  235. videoHyperaxe({ controls: true, src: `/blob/${encodeURIComponent(content.url)}`, type: content.mimeType || 'video/mp4', width: '640', height: '360' }),
  236. br(),
  237. content.tags && content.tags.length
  238. ? div({ class: 'card-tags' }, content.tags.map(tag =>
  239. a({ href: `/search?query=%23${encodeURIComponent(tag)}`, class: 'tag-link' }, `#${tag}`)
  240. ))
  241. : null
  242. ) : null;
  243. case 'document':
  244. return div({ class: 'search-document' },
  245. content.title ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.documentTitleLabel + ':'), span({ class: 'card-value' }, content.title)) : null,
  246. br(),
  247. content.description ? div({ class: 'card-field' }, span({ class: 'card-value' }, content.description)) : null,
  248. br(),
  249. div({
  250. id: `pdf-container-${content.key || content.url}`,
  251. class: 'pdf-viewer-container',
  252. 'data-pdf-url': `/blob/${encodeURIComponent(content.url)}`
  253. }),
  254. br(),
  255. content.tags && content.tags.length
  256. ? div({ class: 'card-tags' }, content.tags.map(tag =>
  257. a({ href: `/search?query=%23${encodeURIComponent(tag)}`, class: 'tag-link' }, `#${tag}`)
  258. ))
  259. : null
  260. );
  261. case 'market':
  262. return div({ class: 'search-market' },
  263. content.title ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.title + ':'), span({ class: 'card-value' }, content.title)) : null,
  264. content.description ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.searchDescription + ':'), span({ class: 'card-value' }, content.description)) : null,
  265. content.item_type ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.marketItemType + ':'), span({ class: 'card-value' }, content.item_type.toUpperCase())) : null,
  266. content.status ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.marketItemCondition + ':'), span({ class: 'card-value' }, content.status)) : null,
  267. content.deadline ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.marketItemDeadline + ':'), span({ class: 'card-value' }, new Date(content.deadline).toLocaleString())) : null,
  268. br(),
  269. blobImg(content.image),
  270. br(),
  271. content.seller ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.marketItemSeller + ':'), span({ class: 'card-value' }, a({ class: "user-link", href: `/author/${encodeURIComponent(content.seller)}` }, content.seller))) : null,
  272. content.stock ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.marketItemStock + ':'), span({ class: 'card-value' }, content.stock || 'N/A')) : null,
  273. content.price ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.searchPriceLabel + ':'), span({ class: 'card-value' }, `${content.price} ECO`)) : null,
  274. content.condition ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.searchDescription + ':'), span({ class: 'card-value' }, content.condition)) : null,
  275. content.includesShipping ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.marketItemIncludesShipping + ':'), span({ class: 'card-value' }, `${content.includesShipping ? i18n.YESLabel : i18n.NOLabel}`)) : null,
  276. content.auctions_poll && content.auctions_poll.length > 0
  277. ? div({ class: 'auction-info' },
  278. p(i18n.marketAuctionBids),
  279. table({ class: 'auction-bid-table' },
  280. tr(
  281. th(i18n.marketAuctionBidTime),
  282. th(i18n.marketAuctionUser),
  283. th(i18n.marketAuctionBidAmount)
  284. ),
  285. content.auctions_poll.map(bid => {
  286. const [userId, bidAmount, bidTime] = bid.split(':');
  287. return tr(
  288. td(moment(bidTime).format('YYYY-MM-DD HH:mm:ss')),
  289. td(a({ href: `/author/${encodeURIComponent(userId)}` }, userId)),
  290. td(`${parseFloat(bidAmount).toFixed(6)} ECO`)
  291. );
  292. })
  293. )
  294. )
  295. : null,
  296. content.tags && content.tags.length
  297. ? div({ class: 'card-tags' }, content.tags.map(tag =>
  298. a({ href: `/search?query=%23${encodeURIComponent(tag)}`, class: 'tag-link' }, `#${tag}`)
  299. ))
  300. : null
  301. );
  302. case 'bookmark':
  303. return div({ class: 'search-bookmark' },
  304. content.description ? div({ class: 'card-field' }, span({ class: 'card-value' }, content.description)) : null, br(),
  305. content.url ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.bookmarkUrlLabel + ':'), span({ class: 'card-value' }, a({ href: content.url, target: '_blank' }, content.url))) : null,br(),
  306. content.category ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.bookmarkCategory + ':'), span({ class: 'card-value' }, content.category)) : null,
  307. content.lastVisit ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.bookmarkLastVisit + ':'), span({ class: 'card-value' }, new Date(content.lastVisit).toLocaleString())) : null,
  308. content.tags && content.tags.length
  309. ? div({ class: 'card-tags' }, content.tags.map(tag =>
  310. a({ href: `/search?query=%23${encodeURIComponent(tag)}`, class: 'tag-link' }, `#${tag}`)
  311. ))
  312. : null
  313. );
  314. case 'task':
  315. return div({ class: 'search-task' },
  316. content.title ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.taskTitleLabel + ':'), span({ class: 'card-value' }, content.title)) : null,
  317. content.description ? div({ class: 'card-field', style: 'display:flex;flex-direction:column;' }, span({ class: 'card-label' }, i18n.searchDescription + ':'), p({ class: 'card-value', style: 'white-space:pre-wrap;margin-top:4px;' }, content.description)) : null,
  318. content.location ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.searchLocationLabel + ':'), span({ class: 'card-value' }, content.location)) : null,
  319. content.status ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.searchStatusLabel + ':'), span({ class: 'card-value' }, content.status)) : null,
  320. content.priority ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.searchPriorityLabel + ':'), span({ class: 'card-value' }, content.priority)) : null,
  321. typeof content.isPublic === 'boolean' ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.searchIsPublicLabel + ':'), span({ class: 'card-value' }, content.isPublic ? i18n.YESLabel : i18n.NOLabel)) : null,
  322. content.startTime ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.taskStartTimeLabel + ':'), span({ class: 'card-value' }, new Date(content.startTime).toLocaleString())) : null,
  323. content.endTime ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.taskEndTimeLabel + ':'), span({ class: 'card-value' }, new Date(content.endTime).toLocaleString())) : null,
  324. Array.isArray(content.assignees) ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.taskAssignees + ':'), span({ class: 'card-value' }, content.assignees.length)) : null,
  325. content.tags && content.tags.length
  326. ? div({ class: 'card-tags' }, content.tags.map(tag =>
  327. a({ href: `/search?query=%23${encodeURIComponent(tag)}`, class: 'tag-link' }, `#${tag}`)
  328. ))
  329. : null
  330. );
  331. case 'report':
  332. return div({ class: 'search-report' },
  333. content.title ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.reportsTitleLabel + ':'), span({ class: 'card-value' }, content.title)) : null,
  334. content.status ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.searchStatusLabel + ':'), span({ class: 'card-value' }, content.status)) : null,
  335. content.severity ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.reportsSeverity + ':'), span({ class: 'card-value' }, content.severity)) : null,
  336. content.category ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.searchCategoryLabel + ':'), span({ class: 'card-value' }, content.category)) : null,
  337. content.description ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.searchDescription + ':'), span({ class: 'card-value' }, content.description)) : null,
  338. br(),
  339. content.image ? img({ src: `/blob/${encodeURIComponent(content.image)}` }) : null,
  340. br(),
  341. typeof content.confirmations === 'number' ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.reportsConfirmations + ':'), span({ class: 'card-value' }, content.confirmations)) : null,
  342. content.tags && content.tags.length
  343. ? div({ class: 'card-tags' }, content.tags.map(tag =>
  344. a({ href: `/search?query=%23${encodeURIComponent(tag)}`, class: 'tag-link' }, `#${tag}`)
  345. ))
  346. : null
  347. );
  348. case 'transfer':
  349. return div({ class: 'search-transfer' },
  350. content.concept ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.transfersConcept + ':'), span({ class: 'card-value' }, content.concept)) : null,
  351. content.deadline ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.transfersDeadline + ':'), span({ class: 'card-value' }, content.deadline)) : null,
  352. content.status ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.transfersStatus + ':'), span({ class: 'card-value' }, content.status)) : null,
  353. content.amount ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.transfersAmount + ':'), span({ class: 'card-value' }, content.amount)) : null,
  354. br(),
  355. content.from ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.transfersFrom + ':'), span({ class: 'card-value' }, a({ class: "user-link", href: `/author/${encodeURIComponent(content.from)}` }, content.from))) : null,
  356. content.to ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.transfersTo + ':'), span({ class: 'card-value' }, a({ class: "user-link", href: `/author/${encodeURIComponent(content.to)}` }, content.to))) : null,
  357. br(),
  358. content.confirmedBy && content.confirmedBy.length
  359. ? h2({ class: 'card-field' }, span({ class: 'card-label' }, i18n.transfersConfirmations + ':'), span({ class: 'card-value' }, content.confirmedBy.length))
  360. : null,
  361. content.tags && content.tags.length
  362. ? div({ class: 'card-tags' }, content.tags.map(tag =>
  363. a({ href: `/search?query=%23${encodeURIComponent(tag)}`, class: 'tag-link' }, `#${tag}`)
  364. ))
  365. : null
  366. );
  367. case 'curriculum':
  368. return div({ class: 'search-curriculum' },
  369. content.name ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.cvNameLabel + ':'), span({ class: 'card-value' }, content.name)) : null,
  370. content.description ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.cvDescriptionLabel + ':'), span({ class: 'card-value' }, content.description)) : null,
  371. content.photo ? img({ src: `/blob/${encodeURIComponent(content.photo)}`, class: 'curriculum-photo' }) : null,
  372. content.location ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.cvLocationLabel + ':'), span({ class: 'card-value' }, content.location)) : null,
  373. content.status ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.cvStatusLabel + ':'), span({ class: 'card-value' }, content.status)) : null,
  374. content.preferences ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.cvPreferencesLabel + ':'), span({ class: 'card-value' }, content.preferences)) : null,
  375. Array.isArray(content.personalSkills) && content.personalSkills.length
  376. ? div({ class: 'card-field' }, content.personalSkills.map(skill =>
  377. a({ href: `/search?query=%23${encodeURIComponent(skill)}`, class: 'tag-link' }, `#${skill}`)
  378. )) : null,
  379. Array.isArray(content.personalExperiences) && content.personalExperiences.length
  380. ? div({ class: 'card-field' }, content.personalExperiences.map(exp => p(exp))) : null,
  381. Array.isArray(content.oasisExperiences) && content.oasisExperiences.length
  382. ? div({ class: 'card-field' }, content.oasisExperiences.map(exp => p(exp))) : null,
  383. Array.isArray(content.oasisSkills) && content.oasisSkills.length
  384. ? div({ class: 'card-field' }, content.oasisSkills.map(skill => p(skill))) : null,
  385. Array.isArray(content.educationExperiences) && content.educationExperiences.length
  386. ? div({ class: 'card-field' }, content.educationExperiences.map(exp => p(exp))) : null,
  387. Array.isArray(content.educationalSkills) && content.educationalSkills.length
  388. ? div({ class: 'card-field' }, content.educationalSkills.map(skill =>
  389. a({ href: `/search?query=%23${encodeURIComponent(skill)}`, class: 'tag-link' }, `#${skill}`)
  390. )) : null,
  391. Array.isArray(content.languages) && content.languages.length
  392. ? div({ class: 'card-field' }, content.languages.map(lang => p(lang))) : null,
  393. Array.isArray(content.professionalExperiences) && content.professionalExperiences.length
  394. ? div({ class: 'card-field' }, content.professionalExperiences.map(exp => p(exp))) : null,
  395. Array.isArray(content.professionalSkills) && content.professionalSkills.length
  396. ? div({ class: 'card-field' }, content.professionalSkills.map(skill => p(skill))) : null
  397. );
  398. case 'bankWallet':
  399. return div({ class: 'search-bank-wallet' },
  400. content.address ? div({ class: 'card-field' },
  401. span({ class: 'card-label' }, i18n.bankWalletConnected + ':' ),
  402. span({ class: 'card-value' }, content.address)
  403. ) : null
  404. );
  405. case 'bankClaim':
  406. return div({ class: 'search-bank-claim' },
  407. div({ class: 'card-field' },
  408. span({ class: 'card-label' }, i18n.bankUbiReceived + ':' ),
  409. span({ class: 'card-value' }, `${Number(content.amount || 0).toFixed(6)} ECO`)
  410. ),
  411. content.epochId ? div({ class: 'card-field' },
  412. span({ class: 'card-label' }, i18n.bankEpochShort + ':' ),
  413. span({ class: 'card-value' }, content.epochId)
  414. ) : null,
  415. content.allocationId ? div({ class: 'card-field' },
  416. span({ class: 'card-label' }, i18n.bankAllocId + ':' ),
  417. span({ class: 'card-value' }, content.allocationId)
  418. ) : null,
  419. content.txid ? div({ class: 'card-field' },
  420. span({ class: 'card-label' }, i18n.bankTx + ':' ),
  421. a({ href: `https://ecoin.03c8.net/blockexplorer/search?q=${content.txid}`, target: '_blank' }, content.txid)
  422. ) : null
  423. );
  424. case 'job':
  425. return div({ class: 'search-job' },
  426. content.title ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.title + ':'), span({ class: 'card-value' }, content.title)) : null,
  427. content.salary ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.jobSalary + ':'), span({ class: 'card-value' }, `${content.salary} ECO`)) : null,
  428. content.status ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.jobStatus + ':'), span({ class: 'card-value' }, content.status.toUpperCase())) : null,
  429. content.job_type ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.jobType + ':'), span({ class: 'card-value' }, content.job_type.toUpperCase())) : null,
  430. content.location ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.jobLocation + ':'), span({ class: 'card-value' }, String(content.location).toUpperCase())) : null,
  431. content.vacants ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.jobVacants + ':'), span({ class: 'card-value' }, content.vacants)) : null,
  432. Array.isArray(content.subscribers) ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.jobSubscribers + ':'), span({ class: 'card-value' }, `${content.subscribers.length}`)) : null
  433. );
  434. case 'forum':
  435. return div({ class: 'search-forum' },
  436. content.root ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.title + ':'), span({ class: 'card-value' }, content.title || '')) : div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.title + ':'), span({ class: 'card-value' }, content.title || '')),
  437. content.text ? div({ class: 'card-field' }, span({ class: 'card-value' }, content.text)) : null
  438. );
  439. case 'vote':
  440. return div({ class: 'search-vote-link' },
  441. content.vote && content.vote.link ? p(a({ href: `/thread/${encodeURIComponent(content.vote.link)}#${encodeURIComponent(content.vote.link)}`, class: 'activityVotePost' }, content.vote.link)) : null
  442. );
  443. case 'contact':
  444. return div({ class: 'search-contact' },
  445. content.contact ? p(a({ href: `/author/${encodeURIComponent(content.contact)}`, class: 'activitySpreadInhabitant2' }, content.contact)) : null
  446. );
  447. case 'pub':
  448. return div({ class: 'search-pub' },
  449. content.address && content.address.key ? p(a({ href: `/author/${encodeURIComponent(content.address.key)}`, class: 'activitySpreadInhabitant2' }, content.address.key)) : null
  450. );
  451. case 'shop':
  452. return div({ class: 'search-shop' },
  453. content.title ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.title + ':'), span({ class: 'card-value' }, content.title)) : null,
  454. blobImg(content.image),
  455. content.shortDescription ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.searchDescription + ':'), span({ class: 'card-value' }, content.shortDescription)) : null,
  456. content.visibility ? div({ class: 'card-field' }, span({ class: 'card-label' }, (i18n.shopStatus || 'STATUS') + ':'), span({ class: 'card-value' }, content.visibility)) : null,
  457. content.location ? div({ class: 'card-field' }, span({ class: 'card-label' }, (i18n.searchLocationLabel || 'LOCATION') + ':'), span({ class: 'card-value' }, content.location)) : null,
  458. content.tags && content.tags.length
  459. ? div({ class: 'card-tags' }, content.tags.map(tag => a({ href: `/search?query=%23${encodeURIComponent(tag)}`, class: 'tag-link' }, `#${tag}`)))
  460. : null
  461. );
  462. case 'shopProduct':
  463. return div({ class: 'search-shop-product' },
  464. content.title ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.title + ':'), span({ class: 'card-value' }, content.title)) : null,
  465. blobImg(content.image),
  466. content.description ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.searchDescription + ':'), span({ class: 'card-value' }, content.description)) : null,
  467. content.price ? div({ class: 'card-field' }, span({ class: 'card-label' }, (i18n.searchPriceLabel || 'PRICE') + ':'), span({ class: 'card-value' }, `${content.price} ECO`)) : null,
  468. content.stock !== undefined ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.marketItemStock + ':'), span({ class: 'card-value' }, content.stock)) : null
  469. );
  470. case 'chat':
  471. return div({ class: 'search-chat' },
  472. content.title ? div({ class: 'card-field' }, span({ class: 'card-label' }, (i18n.chatsTitle || 'Chat') + ':'), span({ class: 'card-value' }, content.title)) : null,
  473. content.description ? div({ class: 'card-field' }, span({ class: 'card-label' }, (i18n.chatDescription || 'Description') + ':'), span({ class: 'card-value' }, content.description)) : null,
  474. content.category ? div({ class: 'card-field' }, span({ class: 'card-label' }, (i18n.chatCategoryLabel || 'Category') + ':'), span({ class: 'card-value' }, content.category)) : null,
  475. content.status ? div({ class: 'card-field' }, span({ class: 'card-label' }, (i18n.chatStatus || 'STATUS') + ':'), span({ class: 'card-value' }, content.status)) : null
  476. );
  477. case 'pad':
  478. return div({ class: 'search-pad' },
  479. content.title ? div({ class: 'card-field' }, span({ class: 'card-label' }, (i18n.padTitle || 'Pad') + ':'), span({ class: 'card-value' }, content.title)) : null,
  480. content.status ? div({ class: 'card-field' }, span({ class: 'card-label' }, (i18n.padStatusLabel || 'Status') + ':'), span({ class: 'card-value' }, content.status)) : null,
  481. content.deadline ? div({ class: 'card-field' }, span({ class: 'card-label' }, (i18n.padDeadlineLabel || 'Deadline') + ':'), span({ class: 'card-value' }, content.deadline)) : null
  482. );
  483. case 'gameScore':
  484. return div({ class: 'search-game' },
  485. content.game ? div({ class: 'game-row' },
  486. img({ src: `/game-assets/${content.game}/thumbnail.svg`, alt: content.game, class: 'game-scoring-thumb', loading: 'lazy' }),
  487. div({ class: 'game-row-body' },
  488. h2({ class: 'game-card-title' }, content.game.charAt(0).toUpperCase() + content.game.slice(1)),
  489. content.score !== undefined ? div({ class: 'card-field' }, span({ class: 'card-label' }, (i18n.gamesHallScore || 'Score') + ':'), span({ class: 'card-value' }, String(content.score))) : null,
  490. a({ href: `/games/${encodeURIComponent(content.game)}`, class: 'filter-btn' }, i18n.gamesPlayButton || 'PLAY!')
  491. )
  492. ) : null
  493. );
  494. case 'map':
  495. return div({ class: 'search-map' },
  496. content.title ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.title + ':'), span({ class: 'card-value' }, content.title)) : null,
  497. content.description ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.mapDescriptionLabel + ':'), span({ class: 'card-value' }, content.description)) : null,
  498. content.lat && content.lng ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.mapLocationTitle + ':'), span({ class: 'card-value' }, `${content.lat}, ${content.lng}`)) : null,
  499. content.mapType ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.mapTypeLabel + ':'), span({ class: 'card-value' }, content.mapType)) : null,
  500. content.tags && content.tags.length
  501. ? div({ class: 'card-tags' }, content.tags.map(tag =>
  502. a({ href: `/search?query=%23${encodeURIComponent(tag)}`, class: 'tag-link' }, `#${tag}`)
  503. ))
  504. : null
  505. );
  506. default:
  507. return div({ class: 'styled-text', innerHTML: sanitizeHtml(renderTextWithStyles(content.text || content.description || content.title || '[no content]')) });
  508. }
  509. };
  510. const resultSection = Object.entries(results).length > 0
  511. ? Object.entries(results).map(([key, msgs]) =>
  512. div(
  513. { class: "search-result-group" },
  514. h2(i18n[key + "Label"] || key.toUpperCase()),
  515. ...msgs.map((msg) => {
  516. const content = msg.value.content || {};
  517. const created = new Date(msg.timestamp).toLocaleString();
  518. if (content.type === 'document') hasDocument = true;
  519. const contentHtml = renderContentHtml(content);
  520. let author;
  521. let authorUrl = '#';
  522. if (content.type === 'market') {
  523. author = content.seller || i18n.anonymous || "Anonymous";
  524. authorUrl = `/author/${encodeURIComponent(content.seller)}`;
  525. } else if (content.type === 'event') {
  526. author = content.organizer || i18n.anonymous || "Anonymous";
  527. authorUrl = `/author/${encodeURIComponent(content.organizer)}`;
  528. } else if (content.type === 'transfer') {
  529. author = content.from || i18n.anonymous || "Anonymous";
  530. authorUrl = `/author/${encodeURIComponent(content.from)}`;
  531. } else if (content.type === 'post' || content.type === 'about') {
  532. author = msg.value.author || i18n.anonymous || "Anonymous";
  533. authorUrl = `/author/${encodeURIComponent(msg.value.author)}`;
  534. } else if (content.type === 'report') {
  535. author = content.author || i18n.anonymous || "Anonymous";
  536. authorUrl = `/author/${encodeURIComponent(content.author || 'Anonymous')}`;
  537. } else if (content.type === 'votes') {
  538. author = content.createdBy || i18n.anonymous || "Anonymous";
  539. authorUrl = `/author/${encodeURIComponent(content.createdBy || 'Anonymous')}`;
  540. } else if (content.type === 'shop' || content.type === 'shopProduct' || content.type === 'chat' || content.type === 'gameScore') {
  541. author = content.author || content.player || msg.value.author || i18n.anonymous || "Anonymous";
  542. authorUrl = `/author/${encodeURIComponent(content.author || content.player || msg.value.author || 'Anonymous')}`;
  543. } else {
  544. author = content.author;
  545. authorUrl = `/author/${encodeURIComponent(content.author || 'Anonymous')}`;
  546. }
  547. const contentId = msg.key;
  548. const detailsButton = form({ method: "GET", action: getViewDetailsActionForSearch(content.type, contentId, content) },
  549. button({ type: "submit", class: "filter-btn" }, i18n.viewDetails)
  550. );
  551. return div({ class: 'result-item' }, [
  552. detailsButton,
  553. br(),
  554. contentHtml,
  555. author
  556. ? p({ class: 'card-footer' },
  557. span({ class: 'date-link' }, `${created} ${i18n.performed} `),
  558. a({ href: authorUrl, class: 'user-link' }, `${author}`)
  559. ): null,
  560. ]);
  561. })
  562. )
  563. )
  564. : div({ class: 'no-results' }, p(i18n.noResultsFound));
  565. let html = template(
  566. hashtag ? `#${hashtag}` : i18n.searchTitle,
  567. section(
  568. div({ class: "tags-header" },
  569. h2(hashtag ? `#${hashtag}` : i18n.searchTitle),
  570. p(hashtag ? i18n.hashtagDescription : i18n.searchDescriptionLabel)
  571. ),
  572. form(
  573. { action: "/search", method: "POST", class: "search-form" },
  574. div({ class: "search-bar" },
  575. filterSelect,
  576. resultsPerPageSelect,
  577. searchInput,
  578. br(), br(),
  579. button({ type: "submit" }, i18n.searchSubmit)
  580. )
  581. )
  582. ),
  583. section(resultSection)
  584. );
  585. if (hasDocument) {
  586. html += `
  587. <script type="module" src="/js/pdf.min.mjs"></script>
  588. <script src="/js/pdf-viewer.js"></script>
  589. `;
  590. }
  591. return html;
  592. };
  593. exports.searchView = searchView;