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