mirror of
https://github.com/PaiGramTeam/luoxu-api-pub.git
synced 2024-11-22 07:08:05 +00:00
make it more suitable for personal use
This commit is contained in:
parent
6808de659d
commit
c66d89e317
@ -5,6 +5,7 @@
|
||||
import { sleep } from './util.js'
|
||||
|
||||
const LUOXU_URL = 'https://lab.lilydjwg.me/luoxu'
|
||||
const islocal = LUOXU_URL.indexOf('http://localhost') === 0
|
||||
let groups = []
|
||||
let group
|
||||
let query
|
||||
@ -20,12 +21,7 @@
|
||||
function parse_hash() {
|
||||
const hash = location.hash
|
||||
if(hash) {
|
||||
const info = new Map()
|
||||
for(const pair of hash.substring(1).split('&')){
|
||||
const [key, value] = pair.split('=')
|
||||
info.set(key, decodeURIComponent(value))
|
||||
}
|
||||
return info
|
||||
return new URLSearchParams(hash.substring(1))
|
||||
}
|
||||
}
|
||||
|
||||
@ -81,7 +77,10 @@
|
||||
if(info.has('q')) {
|
||||
query = info.get('q')
|
||||
}
|
||||
if(group && query) {
|
||||
if(info.has('sender')) {
|
||||
sender = info.get('sender')
|
||||
}
|
||||
if((group || islocal) && query) {
|
||||
result = null
|
||||
do_search()
|
||||
}
|
||||
@ -89,28 +88,35 @@
|
||||
}
|
||||
|
||||
async function do_search(more) {
|
||||
if(!group) {
|
||||
if(!group && !islocal) {
|
||||
error = '请选择要搜索的群组'
|
||||
return
|
||||
}
|
||||
if(!query) {
|
||||
if(!query && !islocal) {
|
||||
error = '请输入搜索关键字'
|
||||
return
|
||||
}
|
||||
error = ''
|
||||
console.log(`searching ${query} for group ${group}, older than ${more}, from ${sender}`)
|
||||
let q = `g=${group}&q=${encodeURIComponent(query)}`
|
||||
const q = new URLSearchParams()
|
||||
if(group) {
|
||||
q.append('g', group)
|
||||
}
|
||||
if(query) {
|
||||
q.append('q', query)
|
||||
}
|
||||
if(sender) {
|
||||
q += `&sender=${sender}`
|
||||
q.append('sender', sender)
|
||||
}
|
||||
let url
|
||||
const qstr = q.toString()
|
||||
if(!more) {
|
||||
location.hash = `#${q}`
|
||||
location.hash = `#${qstr}`
|
||||
need_update_title = true
|
||||
if(result) {
|
||||
result.messages = []
|
||||
}
|
||||
url = `${LUOXU_URL}/search?${q}`
|
||||
url = `${LUOXU_URL}/search?${qstr}`
|
||||
}else{
|
||||
url = `${LUOXU_URL}/search?${q}&end=${more}`
|
||||
}
|
||||
@ -173,7 +179,7 @@
|
||||
|
||||
{#if result}
|
||||
{#each result.messages as message}
|
||||
<Message msg={message} group={result.group_pub_id} now={now} />
|
||||
<Message msg={message} groupinfo={result.groupinfo} now={now} />
|
||||
{/each}
|
||||
{/if}
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
import { onMount, getContext } from 'svelte'
|
||||
|
||||
export let msg
|
||||
export let group
|
||||
export let groupinfo
|
||||
export let now
|
||||
|
||||
const formatter = new Intl.DateTimeFormat(undefined, {
|
||||
@ -16,6 +16,7 @@
|
||||
let title = format_dt(dt) + (edited ? `\n最后编辑于:${format_dt(edited)}` : '')
|
||||
let relative_dt = format_relative_time(dt, now)
|
||||
let iso_date = dt.toISOString()
|
||||
let msgurl = groupinfo[msg.group_id][0] ? `tg://resolve?domain=${groupinfo[msg.group_id][0]}&post=${msg.id}` : `tg://privatepost?channel=${msg.group_id}&post=${msg.id}`
|
||||
|
||||
function format_relative_time(d1, d2) {
|
||||
// in miliseconds
|
||||
@ -51,7 +52,7 @@
|
||||
<div>
|
||||
<div class="name">{msg.from_name || ' '}</div>
|
||||
<div class="text">{@html msg.html}</div>
|
||||
<div class="time"><a href="tg://resolve?domain={group}&post={msg.id}"><time datetime={iso_date} title={title}>{relative_dt}</time></a></div>
|
||||
<div class="time">{groupinfo[msg.group_id][1]} <a href={msgurl}><time datetime={iso_date} title={title}>{relative_dt}</time></a></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -83,7 +84,7 @@
|
||||
font-size: 0.75em;
|
||||
float: right;
|
||||
}
|
||||
.time > a {
|
||||
.time, .time > a {
|
||||
color: gray;
|
||||
}
|
||||
</style>
|
||||
|
@ -37,7 +37,7 @@
|
||||
}
|
||||
|
||||
async function complete_it() {
|
||||
if(!group || !input.value) {
|
||||
if(!input.value) {
|
||||
return
|
||||
}
|
||||
abort.abort()
|
||||
|
Loading…
Reference in New Issue
Block a user