Fix typecheck
This commit is contained in:
@@ -31,7 +31,7 @@ function getSnow(event) {
|
||||
/** @type {Map<string, Promise<string>>} */
|
||||
const cache = new Map()
|
||||
|
||||
/** @param {string | undefined} url */
|
||||
/** @param {string} url */
|
||||
function timeUntilExpiry(url) {
|
||||
const params = new URL(url).searchParams
|
||||
const ex = params.get("ex")
|
||||
|
||||
@@ -5,6 +5,7 @@ const {convertImageStream} = require("../../m2d/converters/emoji-sheet")
|
||||
const tryToCatch = require("try-to-catch")
|
||||
const {test} = require("supertape")
|
||||
const {router} = require("../../../test/web")
|
||||
const streamWeb = require("stream/web")
|
||||
|
||||
test("web download matrix: access denied if not a known attachment", async t => {
|
||||
const [error] = await tryToCatch(() =>
|
||||
@@ -27,6 +28,7 @@ test("web download matrix: works if a known attachment", async t => {
|
||||
},
|
||||
event,
|
||||
api: {
|
||||
// @ts-ignore
|
||||
async getMedia(mxc, init) {
|
||||
return new Response("", {status: 200, headers: {"content-type": "image/png"}})
|
||||
}
|
||||
|
||||
@@ -54,8 +54,8 @@ function getAPI(event) {
|
||||
const validNonce = new LRUCache({max: 200})
|
||||
|
||||
/**
|
||||
* @param {{type: number, parent_id?: string, position?: number}} channel
|
||||
* @param {Map<string, {type: number, parent_id?: string, position?: number}>} channels
|
||||
* @param {{type: number, parent_id?: string | null, position?: number}} channel
|
||||
* @param {Map<string, {type: number, parent_id?: string | null, position?: number}>} channels
|
||||
*/
|
||||
function getPosition(channel, channels) {
|
||||
let position = 0
|
||||
@@ -65,9 +65,11 @@ function getPosition(channel, channels) {
|
||||
// Categories are size 2000.
|
||||
let foundCategory = channel
|
||||
while (foundCategory.parent_id) {
|
||||
foundCategory = channels.get(foundCategory.parent_id)
|
||||
const f = channels.get(foundCategory.parent_id)
|
||||
assert(f)
|
||||
foundCategory = f
|
||||
}
|
||||
if (foundCategory.type === DiscordTypes.ChannelType.GuildCategory) position = (foundCategory.position + 1) * 2000
|
||||
if (foundCategory.type === DiscordTypes.ChannelType.GuildCategory) position = ((foundCategory.position || 0) + 1) * 2000
|
||||
|
||||
// Categories always appear above what they contain.
|
||||
if (channel.type === DiscordTypes.ChannelType.GuildCategory) position -= 0.5
|
||||
@@ -81,7 +83,7 @@ function getPosition(channel, channels) {
|
||||
// Threads appear below their channel.
|
||||
if ([DiscordTypes.ChannelType.PublicThread, DiscordTypes.ChannelType.PrivateThread, DiscordTypes.ChannelType.AnnouncementThread].includes(channel.type)) {
|
||||
position += 0.5
|
||||
let parent = channels.get(channel.parent_id)
|
||||
let parent = channels.get(channel.parent_id || "")
|
||||
if (parent && parent["position"]) position += parent["position"]
|
||||
}
|
||||
|
||||
@@ -98,7 +100,11 @@ function getChannelRoomsLinks(guild, rooms, roles) {
|
||||
assert(channelIDs)
|
||||
|
||||
let linkedChannels = select("channel_room", ["channel_id", "room_id", "name", "nick"], {channel_id: channelIDs}).all()
|
||||
let linkedChannelsWithDetails = linkedChannels.map(c => ({channel: discord.channels.get(c.channel_id), ...c}))
|
||||
let linkedChannelsWithDetails = linkedChannels.map(c => ({
|
||||
// @ts-ignore
|
||||
/** @type {DiscordTypes.APIGuildChannel} */ channel: discord.channels.get(c.channel_id),
|
||||
...c
|
||||
}))
|
||||
let removedUncachedChannels = dUtils.filterTo(linkedChannelsWithDetails, c => c.channel)
|
||||
let linkedChannelIDs = linkedChannelsWithDetails.map(c => c.channel_id)
|
||||
linkedChannelsWithDetails.sort((a, b) => getPosition(a.channel, discord.channels) - getPosition(b.channel, discord.channels))
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// @ts-check
|
||||
|
||||
const assert = require("assert").strict
|
||||
const {z} = require("zod")
|
||||
const {defineEventHandler, createError, readValidatedBody, setResponseHeader, H3Event} = require("h3")
|
||||
const Ty = require("../../types")
|
||||
@@ -77,7 +78,9 @@ as.router.post("/api/link-space", defineEventHandler(async event => {
|
||||
const existing = select("guild_space", "guild_id", {}, "WHERE guild_id = ? OR space_id = ?").get(guildID, spaceID)
|
||||
if (existing) throw createError({status: 400, message: "Bad Request", data: `Guild ID ${guildID} or space ID ${spaceID} are already bridged and cannot be reused`})
|
||||
|
||||
const via = [inviteRow.mxid.match(/:(.*)/)[1]]
|
||||
const inviteServer = inviteRow.mxid.match(/:(.*)/)?.[1]
|
||||
assert(inviteServer)
|
||||
const via = [inviteServer]
|
||||
|
||||
// Check space exists and bridge is joined
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user