client: use the versions in shared/ where applicable

This commit is contained in:
Reto Brunner 2023-01-29 17:28:03 +01:00
parent 9d34955836
commit e305e23c43
7 changed files with 10 additions and 96 deletions

View file

@ -1,4 +0,0 @@
const matchFormatting =
/\x02|\x1D|\x1F|\x16|\x0F|\x11|\x1E|\x03(?:[0-9]{1,2}(?:,[0-9]{1,2})?)?|\x04(?:[0-9a-f]{6}(?:,[0-9a-f]{6})?)?/gi;
export default (message: string) => message.replace(matchFormatting, "").trim();

View file

@ -1,83 +0,0 @@
import LinkifyIt, {Match} from "linkify-it";
import {Part} from "./merge";
export type LinkPart = Part & {
link: string;
};
type OurMatch = Match & {
noschema?: boolean;
};
LinkifyIt.prototype.normalize = function normalize(match: OurMatch) {
if (!match.schema) {
match.schema = "http:";
match.url = "http://" + match.url;
match.noschema = true;
}
if (match.schema === "//") {
match.schema = "http:";
match.url = "http:" + match.url;
match.noschema = true;
}
if (match.schema === "mailto:" && !/^mailto:/i.test(match.url)) {
match.url = "mailto:" + match.url;
}
};
import tlds from "tlds";
const linkify = LinkifyIt().tlds(tlds).tlds("onion", true);
// Known schemes to detect in text
const commonSchemes = [
"sftp",
"smb",
"file",
"irc",
"ircs",
"svn",
"git",
"steam",
"mumble",
"ts3server",
"svn+ssh",
"ssh",
"gopher",
"gemini",
];
for (const schema of commonSchemes) {
linkify.add(schema + ":", "http:");
}
function findLinks(text: string) {
const matches = linkify.match(text) as OurMatch[];
if (!matches) {
return [];
}
return matches.map(returnUrl);
}
function findLinksWithSchema(text: string) {
const matches = linkify.match(text) as OurMatch[];
if (!matches) {
return [];
}
return matches.filter((url) => !url.noschema).map(returnUrl);
}
function returnUrl(url: OurMatch): LinkPart {
return {
start: url.index,
end: url.lastIndex,
link: url.url,
};
}
export {findLinks, findLinksWithSchema};

View file

@ -2,7 +2,7 @@ import anyIntersection from "./anyIntersection";
import fill from "./fill";
import {ChannelPart} from "./findChannels";
import {EmojiPart} from "./findEmoji";
import {LinkPart} from "./findLinks";
import {LinkPart} from "../../../../shared/linkify";
import {NamePart} from "./findNames";
export type Part = {

View file

@ -3,11 +3,11 @@
import {h as createElement, VNode} from "vue";
import parseStyle from "./ircmessageparser/parseStyle";
import findChannels, {ChannelPart} from "./ircmessageparser/findChannels";
import {findLinks, LinkPart} from "./ircmessageparser/findLinks";
import findEmoji, {EmojiPart} from "./ircmessageparser/findEmoji";
import findNames, {NamePart} from "./ircmessageparser/findNames";
import merge, {MergedParts, Part} from "./ircmessageparser/merge";
import findChannels from "./ircmessageparser/findChannels";
import {findLinks} from "../../../shared/linkify";
import findEmoji from "./ircmessageparser/findEmoji";
import findNames from "./ircmessageparser/findNames";
import merge, {MergedParts} from "./ircmessageparser/merge";
import emojiMap from "./fullnamemap.json";
import LinkPreviewToggle from "../../components/LinkPreviewToggle.vue";
import LinkPreviewFileSize from "../../components/LinkPreviewFileSize.vue";

View file

@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/restrict-plus-operands */
import socket from "../socket";
import cleanIrcMessage from "../helpers/ircmessageparser/cleanIrcMessage";
import {cleanIrcMessage} from "../../../shared/irc";
import {store} from "../store";
import {switchToChannel} from "../router";
import {ClientChan, ClientMention, ClientMessage, NetChan} from "../types";

View file

@ -1,7 +1,8 @@
{
"extends": "../tsconfig.base.json" /* Path to base configuration file to inherit from. Requires TypeScript version 2.1 or later. */,
"include": [
"./**/*"
"./**/*",
"../shared"
] /* Specifies a list of glob patterns that match files to be included in compilation. If no 'files' or 'include' property is present in a tsconfig.json, the compiler defaults to including all files in the containing directory and subdirectories except those specified by 'exclude'. Requires TypeScript version 2.0 or later. */,
"files": [
"../package.json",

View file

@ -58,7 +58,7 @@ const config: webpack.Configuration = {
},
{
test: /\.ts$/i,
include: [path.resolve(__dirname, "client")],
include: [path.resolve(__dirname, "client"), path.resolve(__dirname, "shared")],
exclude: path.resolve(__dirname, "node_modules"),
use: {
loader: "babel-loader",