Merge branch 'opensearch' into 'master'
add opensearch support See merge request framasoft/peertube/search-index!4
This commit is contained in:
commit
b587ca5d08
25
server.ts
25
server.ts
|
@ -15,10 +15,10 @@ import { VideosIndexer } from './server/lib/schedulers/videos-indexer'
|
|||
import { initVideosIndex } from './server/lib/elastic-search-videos'
|
||||
import { initChannelsIndex } from './server/lib/elastic-search-channels'
|
||||
import { join } from 'path'
|
||||
import { send } from 'process'
|
||||
import { readFile } from 'fs-extra'
|
||||
|
||||
const app = express()
|
||||
const url = getWebserverUrl()
|
||||
|
||||
app.use(morgan('combined', {
|
||||
stream: { write: logger.info.bind(logger) }
|
||||
|
@ -44,14 +44,29 @@ app.use('/img/', express.static(join(__dirname, '../client/dist/img')))
|
|||
|
||||
let indexHTML: string
|
||||
|
||||
app.use('/opensearch.xml', async function (req, res) {
|
||||
return res.send(`<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
|
||||
<ShortName>${CONFIG.SEARCH_INSTANCE.NAME}</ShortName>
|
||||
<Description>${CONFIG.SEARCH_INSTANCE.DESCRIPTION}</Description>
|
||||
<Image height="64" width="64" type="image/png">${url}/img/favicon.png</Image>
|
||||
<Language>*</Language>
|
||||
<Url type="text/html" rel="results" template="${url}/search?search={searchTerms}"/>
|
||||
<Url type="application/opensearchdescription+xml" rel="self" template="${url}/opensearch.xml"/>
|
||||
<Query role="example" searchTerms="peertube"/>
|
||||
<SyndicationRight>open</SyndicationRight>
|
||||
<AdultContent>true</AdultContent>
|
||||
<InputEncoding>UTF-8</InputEncoding>
|
||||
<OutputEncoding>UTF-8</OutputEncoding>
|
||||
<Developer>Framasoft: contact.framasoft.org</Developer>
|
||||
</OpenSearchDescription>`).type('application/xml').status(200).end()
|
||||
})
|
||||
app.use('/*', async function (req, res) {
|
||||
res.set('Content-Type', 'text/html; charset=UTF-8')
|
||||
|
||||
if (indexHTML) return res.send(indexHTML)
|
||||
|
||||
const buffer = await readFile(join(__dirname, '../client/dist/index.html'))
|
||||
|
||||
const url = getWebserverUrl()
|
||||
const title = CONFIG.SEARCH_INSTANCE.NAME
|
||||
const description = CONFIG.SEARCH_INSTANCE.DESCRIPTION
|
||||
|
||||
|
@ -69,7 +84,9 @@ app.use('/*', async function (req, res) {
|
|||
<meta name="twitter:creator" content="@chocobozzz">
|
||||
<meta name="twitter:title" content="${title}">
|
||||
<meta name="twitter:description" content="${description}">
|
||||
<meta name="twitter:image" content="${url}/img/card-opengraph.png">`
|
||||
<meta name="twitter:image" content="${url}/img/card-opengraph.png">
|
||||
|
||||
<link rel="search" type="application/opensearchdescription+xml" title="${title}" href="${url}/opensearch.xml" />`
|
||||
|
||||
indexHTML = buffer.toString()
|
||||
indexHTML = indexHTML.replace('</head>', tags + '</head>')
|
||||
|
|
Loading…
Reference in New Issue