mirror of
https://github.com/the-draupnir-project/Draupnir.git
synced 2026-06-06 07:41:18 +00:00
Add Avatar Customisation Commands (#1108)
Tests / Build & Lint (push) Failing after 2m30s
Tests / Unit tests (push) Successful in 2m58s
Tests / Integration tests (push) Failing after 14s
Tests / Application Service Integration tests (push) Failing after 16s
GHCR - Development Branches / ghcr-publish (push) Failing after 13m10s
Docker Hub - Develop / docker-latest (push) Failing after 14m5s
Tests / Build & Lint (push) Failing after 2m30s
Tests / Unit tests (push) Successful in 2m58s
Tests / Integration tests (push) Failing after 14s
Tests / Application Service Integration tests (push) Failing after 16s
GHCR - Development Branches / ghcr-publish (push) Failing after 13m10s
Docker Hub - Develop / docker-latest (push) Failing after 14m5s
* Add Avatar Command to bot mode and AS mode * Add changesets * Move MXC URI validation to matrix basic types * Fix MediaID being mixed case when its exempt from usual case rules. * Update changeset * Integrate Gnuxie Review Feedback * Fix linting errors * Fix having forgotten to run prettier. * Integrate Gnuxie review feedback. * Fix version.txt.tmp files
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
// Copyright 2026 Catalan Lover <catalanlover@protonmail.com>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import {
|
||||
StringMediaURI,
|
||||
isStringMediaURI,
|
||||
MediaURIMediaID,
|
||||
MediaURIServerName,
|
||||
} from "./StringMediaURI";
|
||||
|
||||
test("isStringMediaURI accepts valid MXC URIs", function () {
|
||||
expect(isStringMediaURI("mxc://matrix.org/abc123")).toBe(true);
|
||||
expect(isStringMediaURI("mxc://matrix.org:8888/abc123")).toBe(true);
|
||||
expect(isStringMediaURI("mxc://1.2.3.4/abc123")).toBe(true);
|
||||
expect(isStringMediaURI("mxc://1.2.3.4:1234/abc123")).toBe(true);
|
||||
expect(isStringMediaURI("mxc://[1234:5678::abcd]/abc123")).toBe(true);
|
||||
expect(isStringMediaURI("mxc://[1234:5678::abcd]:5678/abc123")).toBe(true);
|
||||
expect(isStringMediaURI("mxc://[::1]/abc123")).toBe(true);
|
||||
expect(isStringMediaURI("mxc://[::1]:8008/abc123")).toBe(true);
|
||||
expect(isStringMediaURI("mxc://matrix.org/a_b-c123")).toBe(true);
|
||||
});
|
||||
|
||||
test("isStringMediaURI rejects invalid MXC URIs", function () {
|
||||
expect(isStringMediaURI("invalid://matrix.org/abc123")).toBe(false);
|
||||
expect(isStringMediaURI("mxc://matrix.org")).toBe(false);
|
||||
expect(isStringMediaURI("mxc://matrix.org/abc 123")).toBe(false);
|
||||
expect(isStringMediaURI("mxc://example.com~invalid/abc123")).toBe(false);
|
||||
expect(isStringMediaURI("mxc://matrix.org/abc.def")).toBe(false);
|
||||
expect(isStringMediaURI("mxc://matrix.org/abc~def")).toBe(false);
|
||||
});
|
||||
|
||||
test("StringMediaURI accessors", function () {
|
||||
const uri = StringMediaURI("mxc://[1234:5678::abcd]:5678/abc123");
|
||||
|
||||
expect(MediaURIServerName(uri)).toBe("[1234:5678::abcd]:5678");
|
||||
expect(MediaURIMediaID(uri)).toBe("abc123");
|
||||
});
|
||||
@@ -0,0 +1,49 @@
|
||||
// SPDX-FileCopyrightText: 2026 Catalan Lover <catalanlover@protonmail.com>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import {
|
||||
StringServerName,
|
||||
StringServerNameRegexPart,
|
||||
} from "./StringServerName";
|
||||
|
||||
export const StringMediaURIRegex = new RegExp(
|
||||
`^mxc://(?<serverName>${StringServerNameRegexPart.source})/(?<mediaID>[A-Za-z0-9_-]+)$`
|
||||
);
|
||||
|
||||
export type StringMediaURIBrand = {
|
||||
readonly StringMediaURI: unique symbol;
|
||||
};
|
||||
|
||||
export type StringMediaURI = string & StringMediaURIBrand;
|
||||
|
||||
export function isStringMediaURI(string: string): string is StringMediaURI {
|
||||
return StringMediaURIRegex.test(string);
|
||||
}
|
||||
|
||||
export function StringMediaURI(string: unknown): StringMediaURI {
|
||||
if (typeof string === "string" && isStringMediaURI(string)) {
|
||||
return string;
|
||||
}
|
||||
throw new TypeError("Not a valid StringMediaURI");
|
||||
}
|
||||
|
||||
export function MediaURIServerName(uri: StringMediaURI): StringServerName {
|
||||
const match = StringMediaURIRegex.exec(uri)?.groups?.serverName;
|
||||
if (match === undefined) {
|
||||
throw new TypeError(
|
||||
"Somehow a StringMediaURI was created that is invalid."
|
||||
);
|
||||
}
|
||||
return match as StringServerName;
|
||||
}
|
||||
|
||||
export function MediaURIMediaID(uri: StringMediaURI): string {
|
||||
const match = StringMediaURIRegex.exec(uri)?.groups?.mediaID;
|
||||
if (match === undefined) {
|
||||
throw new TypeError(
|
||||
"Somehow a StringMediaURI was created that is invalid."
|
||||
);
|
||||
}
|
||||
return match;
|
||||
}
|
||||
@@ -8,6 +8,7 @@
|
||||
// </text>
|
||||
|
||||
export * from "./StringEventID";
|
||||
export * from "./StringMediaURI";
|
||||
export * from "./StringRoomAlias";
|
||||
export * from "./StringRoomID";
|
||||
export * from "./StringServerName";
|
||||
|
||||
Reference in New Issue
Block a user