Compare commits

...

5 Commits

9 changed files with 128 additions and 185 deletions

View File

@ -18,4 +18,3 @@ README.old
SECURITY.md
docker-compose.yml
package-lock.json
yarn.lock

View File

@ -4,10 +4,10 @@ RUN apk add --no-cache --virtual=build-dependencies build-base git python3-dev &
USER node
WORKDIR /var/opt/hardlounge-src
ENV THELOUNGE_HOME /var/opt/hardlounge
COPY package.json yarn.lock .
RUN yarn install
COPY . .
#RUN git clone https://git.supernets.org/supernets/hardlounge.git --depth 1 .
RUN yarn install && \
NODE_ENV=production yarn build && \
RUN NODE_ENV=production yarn build && \
yarn link && \
yarn --non-interactive cache clean && \
ln -s /var/opt/hardlounge-src/index.js /var/opt/hardlounge-src/hardlounge

View File

@ -1,37 +1,6 @@
<template>
<div id="version-checker" :class="[store.state.versionStatus]">
<p v-if="store.state.versionStatus === 'loading'">Checking for updates</p>
<p v-if="store.state.versionStatus === 'new-version'">
Hard Lounge <b>{{ store.state.versionData?.latest.version }}</b>
<template v-if="store.state.versionData?.latest.prerelease"> (pre-release) </template>
is now available.
<br />
<a :href="store.state.versionData?.latest.url" target="_blank" rel="noopener">
Read more on GitHub
</a>
</p>
<p v-if="store.state.versionStatus === 'new-packages'">
Hard Lounge is up to date, but there are out of date packages Run
<code>thelounge upgrade</code> on the server to upgrade packages.
</p>
<template v-if="store.state.versionStatus === 'up-to-date'">
<p>Hard Lounge is up to date!</p>
<button
v-if="store.state.versionDataExpired"
id="check-now"
class="btn btn-small"
@click="checkNow"
>
Check now
</button>
</template>
<template v-if="store.state.versionStatus === 'error'">
<p>Information about latest release could not be retrieved.</p>
<button id="check-now" class="btn btn-small" @click="checkNow">Try again</button>
</template>
<p>Check for updates yourself you lazy bum</p>
</div>
</template>

View File

@ -12,21 +12,17 @@
v{{
store.state.serverConfiguration?.version
}}
(<router-link id="view-changelog" to="/changelog"
>release notes</router-link
>)
</small>
</h2>
<div class="about">
<VersionChecker />
<p>
<a
href="https://git.supernets.org/supernets/hardlounge/"
target="_blank"
rel="noopener"
class="website-link"
>Website</a
>Source Code</a
>
</p>
<p>
@ -35,7 +31,7 @@
target="_blank"
rel="noopener"
class="documentation-link"
>Documentation</a
>Documentation (The Lounge)</a
>
</p>
<p>
@ -1228,13 +1224,11 @@
import { defineComponent, ref } from "vue";
import { useStore } from "../../js/store";
import SidebarToggle from "../SidebarToggle.vue";
import VersionChecker from "../VersionChecker.vue";
export default defineComponent({
name: "Help",
components: {
SidebarToggle,
VersionChecker,
SidebarToggle
},
setup() {
const store = useStore();

View File

@ -135,7 +135,6 @@
"eslint-plugin-vue": "9.0.1",
"fork-ts-checker-webpack-plugin": "7.2.13",
"fuzzy": "0.1.3",
"husky": "4.3.8",
"mini-css-extract-plugin": "2.5.3",
"mocha": "9.2.2",
"mousetrap": "1.6.5",
@ -168,10 +167,5 @@
"webpack-cli": "4.9.2",
"webpack-dev-middleware": "5.3.3",
"webpack-hot-middleware": "2.25.4"
},
"husky": {
"hooks": {
"pre-commit": "pretty-quick --staged"
}
}
}

View File

@ -37,12 +37,18 @@ export type LinkPreview = {
thumbActualUrl?: string;
};
export default function (client: Client, chan: Chan, msg: Msg, cleanText: string) {
export default function (
client: Client,
chan: Chan,
msg: Msg,
cleanText: string
) {
if (!Config.values.prefetch) {
return;
}
msg.previews = findLinksWithSchema(cleanText).reduce((cleanLinks: LinkPreview[], link) => {
msg.previews = findLinksWithSchema(cleanText).reduce(
(cleanLinks: LinkPreview[], link) => {
const url = normalizeURL(link.link);
// If the URL is invalid and cannot be normalized, don't fetch it
@ -87,7 +93,9 @@ export default function (client: Client, chan: Chan, msg: Msg, cleanText: string
});
return cleanLinks;
}, []);
},
[]
);
}
function parseHtml(preview, res, client: Client) {
@ -117,7 +125,10 @@ function parseHtml(preview, res, client: Client) {
preview.body = preview.body.substr(0, 300);
}
if (!Config.values.prefetchStorage && Config.values.disableMediaPreview) {
if (
!Config.values.prefetchStorage &&
Config.values.disableMediaPreview
) {
resolve(res);
return;
}
@ -135,12 +146,15 @@ function parseHtml(preview, res, client: Client) {
// Verify that thumbnail pic exists and is under allowed size
if (thumb.length) {
fetch(thumb, {language: client.config.browser?.language || ""})
fetch(thumb, {
language: client.config.browser?.language || "",
})
.then((resThumb) => {
if (
resThumb !== null &&
imageTypeRegex.test(resThumb.type) &&
resThumb.size <= Config.values.prefetchMaxImageSize * 1024
resThumb.size <=
Config.values.prefetchMaxImageSize * 1024
) {
preview.thumbActualUrl = thumb;
}
@ -156,7 +170,11 @@ function parseHtml(preview, res, client: Client) {
}
// TODO: type $
function parseHtmlMedia($: any, preview, client: Client): Promise<FetchRequest> {
function parseHtmlMedia(
$: any,
preview,
client: Client
): Promise<FetchRequest> {
return new Promise((resolve, reject) => {
if (Config.values.disableMediaPreview) {
reject();
@ -183,7 +201,10 @@ function parseHtmlMedia($: any, preview, client: Client): Promise<FetchRequest>
return;
}
$(`meta[property="og:${type}:type"]`).each(function (this: cheerio.Element, i: number) {
$(`meta[property="og:${type}:type"]`).each(function (
this: cheerio.Element,
i: number
) {
const mimeType = $(this).attr("content");
if (!mimeType) {
@ -192,7 +213,9 @@ function parseHtmlMedia($: any, preview, client: Client): Promise<FetchRequest>
if (mediaTypeRegex.test(mimeType)) {
// If we match a clean video or audio tag, parse that as a preview instead
let mediaUrl = $($(`meta[property="og:${type}"]`).get(i)).attr("content");
let mediaUrl = $(
$(`meta[property="og:${type}"]`).get(i)
).attr("content");
if (!mediaUrl) {
return;
@ -216,7 +239,10 @@ function parseHtmlMedia($: any, preview, client: Client): Promise<FetchRequest>
language: client.config.browser?.language || "",
})
.then((resMedia) => {
if (resMedia === null || !mediaTypeRegex.test(resMedia.type)) {
if (
resMedia === null ||
!mediaTypeRegex.test(resMedia.type)
) {
return reject();
}
@ -239,7 +265,13 @@ function parseHtmlMedia($: any, preview, client: Client): Promise<FetchRequest>
});
}
function parse(msg: Msg, chan: Chan, preview: LinkPreview, res: FetchRequest, client: Client) {
function parse(
msg: Msg,
chan: Chan,
preview: LinkPreview,
res: FetchRequest,
client: Client
) {
let promise: Promise<FetchRequest | null> | null = null;
preview.size = res.size;
@ -262,7 +294,10 @@ function parse(msg: Msg, chan: Chan, preview: LinkPreview, res: FetchRequest, cl
case "image/jxl":
case "image/webp":
case "image/avif":
if (!Config.values.prefetchStorage && Config.values.disableMediaPreview) {
if (
!Config.values.prefetchStorage &&
Config.values.disableMediaPreview
) {
return removePreview(msg, preview);
}
@ -330,10 +365,18 @@ function parse(msg: Msg, chan: Chan, preview: LinkPreview, res: FetchRequest, cl
return handlePreview(client, chan, msg, preview, res);
}
void promise.then((newRes) => handlePreview(client, chan, msg, preview, newRes));
void promise.then((newRes) =>
handlePreview(client, chan, msg, preview, newRes)
);
}
function handlePreview(client: Client, chan: Chan, msg: Msg, preview: LinkPreview, res) {
function handlePreview(
client: Client,
chan: Chan,
msg: Msg,
preview: LinkPreview,
res
) {
const thumb = preview.thumbActualUrl || "";
delete preview.thumbActualUrl;
@ -363,7 +406,12 @@ function handlePreview(client: Client, chan: Chan, msg: Msg, preview: LinkPrevie
});
}
function emitPreview(client: Client, chan: Chan, msg: Msg, preview: LinkPreview) {
function emitPreview(
client: Client,
chan: Chan,
msg: Msg,
preview: LinkPreview
) {
// If there is no title but there is preview or description, set title
// otherwise bail out and show no preview
if (!preview.head.length && preview.type === "link") {
@ -396,7 +444,7 @@ function getRequestHeaders(headers: Record<string, string>) {
// Certain websites like Amazon only add <meta> tags to known bots,
// lets pretend to be them to get the metadata
"User-Agent":
"Mozilla/5.0 (compatible; Hard Lounge IRC Client; COLD HARD CHATS; +https://git.supernets.org/supernets/hardlounge)" +
"Mozilla/5.0 (compatible; Hard Lounge IRC Client; COLD HARD CHATS ONLY ON IRC.SUPERNETS.ORG; +https://git.supernets.org/supernets/hardlounge)" +
" facebookexternalhit/1.1 Twitterbot/1.0",
Accept: headers.accept || "*/*",
"X-Purpose": "preview",
@ -442,17 +490,24 @@ function fetch(uri: string, headers: Record<string, string>) {
gotStream
.on("response", function (res) {
contentLength = parseInt(res.headers["content-length"], 10) || 0;
contentLength =
parseInt(res.headers["content-length"], 10) || 0;
contentType = res.headers["content-type"];
if (contentType && imageTypeRegex.test(contentType)) {
// response is an image
// if Content-Length header reports a size exceeding the prefetch limit, abort fetch
// and if file is not to be stored we don't need to download further either
if (contentLength > limit || !Config.values.prefetchStorage) {
if (
contentLength > limit ||
!Config.values.prefetchStorage
) {
gotStream.destroy();
}
} else if (contentType && mediaTypeRegex.test(contentType)) {
} else if (
contentType &&
mediaTypeRegex.test(contentType)
) {
// We don't need to download the file any further after we received content-type header
gotStream.destroy();
} else {
@ -482,7 +537,10 @@ function fetch(uri: string, headers: Record<string, string>) {
let type = "";
// If we downloaded more data then specified in Content-Length, use real data size
const size = contentLength > buffer.length ? contentLength : buffer.length;
const size =
contentLength > buffer.length
? contentLength
: buffer.length;
if (contentType) {
type = contentType.split(/ *; */).shift() || "";

View File

@ -346,7 +346,6 @@ export default async function (
});
}
changelog.checkForUpdates(manager);
});
return server;

View File

@ -16,7 +16,6 @@ describe("Server", function () {
let server;
let logInfoStub: sinon.SinonStub<string[], void>;
let logWarnStub: sinon.SinonStub<string[], void>;
let checkForUpdatesStub: sinon.SinonStub<[manager: ClientManager], void>;
before(async function () {
logInfoStub = sinon.stub(log, "info");
@ -34,7 +33,6 @@ describe("Server", function () {
console.error(`Unhandled log.warn in server tests: ${args.join(" ")}`);
});
checkForUpdatesStub = sinon.stub(changelog, "checkForUpdates");
server = await (await import("../server/server")).default({} as any);
});
@ -43,7 +41,6 @@ describe("Server", function () {
// in case setup crashed for any reason
logInfoStub.restore();
logWarnStub.restore();
checkForUpdatesStub.restore();
server.close(done);
});

View File

@ -2879,11 +2879,6 @@ chrome-trace-event@^1.0.2:
resolved "https://registry.yarnpkg.com/chrome-trace-event/-/chrome-trace-event-1.0.3.tgz#1015eced4741e15d06664a957dbbf50d041e26ac"
integrity sha512-p3KULyQg4S7NIHixdwbGX+nFHkoBiA4YQmyWtjb8XngSKV124nJmRysgAeujbUVb15vh+RvFUfCPqU7rXk+hZg==
ci-info@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/ci-info/-/ci-info-2.0.0.tgz#67a9e964be31a51e15e5010d58e6f12834002f46"
integrity sha512-5tK7EtrZ0N+OLFMthtqOj4fI2Jeb88C4CAZPu25LDVUgXJ0A3Js4PMGqrn0JU1W0Mh1/Z8wZzYPxqUrXeBboCQ==
clean-stack@^2.0.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/clean-stack/-/clean-stack-2.2.0.tgz#ee8472dbb129e727b31e8a10a427dee9dfe4008b"
@ -2989,11 +2984,6 @@ commondir@^1.0.1:
resolved "https://registry.yarnpkg.com/commondir/-/commondir-1.0.1.tgz#ddd800da0c66127393cca5950ea968a3aaf1253b"
integrity sha512-W9pAhw0ja1Edb5GVdIF1mjZw/ASI0AlShXM83UUGe2DVr5TdAPEA1OA8m/g8zWp9x6On7gqufY+FatDbC3MDQg==
compare-versions@^3.6.0:
version "3.6.0"
resolved "https://registry.yarnpkg.com/compare-versions/-/compare-versions-3.6.0.tgz#1a5689913685e5a87637b8d3ffca75514ec41d62"
integrity sha512-W6Af2Iw1z4CB7q4uU4hv646dW9GQuBM+YpC0UvUCWSD8w90SJjp+ujJuXaEMtAXBtSqGfMPuFOVn4/+FlaqfBA==
concat-map@0.0.1:
version "0.0.1"
resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b"
@ -4046,7 +4036,7 @@ find-cache-dir@^3.2.0, find-cache-dir@^3.3.1:
make-dir "^3.0.2"
pkg-dir "^4.1.0"
find-up@5.0.0, find-up@^5.0.0:
find-up@5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/find-up/-/find-up-5.0.0.tgz#4c92819ecb7083561e4f4a240a86be5198f536fc"
integrity sha512-78/PXT1wlLLDgTzDs7sjq9hzz0vXD+zn+7wypEe4fXQxCmdmqfGsEPQxmiCSQI3ajFV91bVSsvNtrJRiW6nGng==
@ -4062,13 +4052,6 @@ find-up@^4.0.0, find-up@^4.1.0:
locate-path "^5.0.0"
path-exists "^4.0.0"
find-versions@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/find-versions/-/find-versions-4.0.0.tgz#3c57e573bf97769b8cb8df16934b627915da4965"
integrity sha512-wgpWy002tA+wgmO27buH/9KzyEOQnKsG/R0yrcjPT9BOFm0zRBVQbZ95nRGXWMywS8YR5knRbpohio0bcJABxQ==
dependencies:
semver-regex "^3.1.2"
flat-cache@^3.0.4:
version "3.1.1"
resolved "https://registry.yarnpkg.com/flat-cache/-/flat-cache-3.1.1.tgz#a02a15fdec25a8f844ff7cc658f03dd99eb4609b"
@ -4634,22 +4617,6 @@ humanize-ms@^1.2.1:
dependencies:
ms "^2.0.0"
husky@4.3.8:
version "4.3.8"
resolved "https://registry.yarnpkg.com/husky/-/husky-4.3.8.tgz#31144060be963fd6850e5cc8f019a1dfe194296d"
integrity sha512-LCqqsB0PzJQ/AlCgfrfzRe3e3+NvmefAdKQhRYpxS4u6clblBoDdzzvHi8fmxKRzvMxPY/1WZWzomPZww0Anow==
dependencies:
chalk "^4.0.0"
ci-info "^2.0.0"
compare-versions "^3.6.0"
cosmiconfig "^7.0.0"
find-versions "^4.0.0"
opencollective-postinstall "^2.0.2"
pkg-dir "^5.0.0"
please-upgrade-node "^3.2.0"
slash "^3.0.0"
which-pm-runs "^1.0.0"
iconv-lite@0.4.24:
version "0.4.24"
resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.24.tgz#2022b4b25fbddc21d2f524974a474aafe733908b"
@ -6043,11 +6010,6 @@ onetime@^5.1.0, onetime@^5.1.2:
dependencies:
mimic-fn "^2.1.0"
opencollective-postinstall@^2.0.2:
version "2.0.3"
resolved "https://registry.yarnpkg.com/opencollective-postinstall/-/opencollective-postinstall-2.0.3.tgz#7a0fff978f6dbfa4d006238fbac98ed4198c3259"
integrity sha512-8AV/sCtuzUeTo8gQK5qDZzARrulB3egtLzFgteqB2tcT4Mw7B8Kt7JcDHmltjz6FOAHsvTevk70gZEbhM4ZS9Q==
optionator@^0.9.1:
version "0.9.3"
resolved "https://registry.yarnpkg.com/optionator/-/optionator-0.9.3.tgz#007397d44ed1872fdc6ed31360190f81814e2c64"
@ -6278,20 +6240,6 @@ pkg-dir@^4.1.0, pkg-dir@^4.2.0:
dependencies:
find-up "^4.0.0"
pkg-dir@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/pkg-dir/-/pkg-dir-5.0.0.tgz#a02d6aebe6ba133a928f74aec20bafdfe6b8e760"
integrity sha512-NPE8TDbzl/3YQYY7CSS228s3g2ollTFnc+Qi3tqmqJp9Vg2ovUpixcJEo2HJScN2Ez+kEaal6y70c0ehqJBJeA==
dependencies:
find-up "^5.0.0"
please-upgrade-node@^3.2.0:
version "3.2.0"
resolved "https://registry.yarnpkg.com/please-upgrade-node/-/please-upgrade-node-3.2.0.tgz#aeddd3f994c933e4ad98b99d9a556efa0e2fe942"
integrity sha512-gQR3WpIgNIKwBMVLkpMUeR3e1/E1y42bqDQZfql+kDeXd8COYfM8PQA4X6y7a8u9Ua9FHmsrrmirW2vHs45hWg==
dependencies:
semver-compare "^1.0.0"
postcss-attribute-case-insensitive@^5.0.0:
version "5.0.2"
resolved "https://registry.yarnpkg.com/postcss-attribute-case-insensitive/-/postcss-attribute-case-insensitive-5.0.2.tgz#03d761b24afc04c09e757e92ff53716ae8ea2741"
@ -7246,16 +7194,6 @@ schema-utils@^4.0.0:
ajv-formats "^2.1.1"
ajv-keywords "^5.1.0"
semver-compare@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/semver-compare/-/semver-compare-1.0.0.tgz#0dee216a1c941ab37e9efb1788f6afc5ff5537fc"
integrity sha512-YM3/ITh2MJ5MtzaM429anh+x2jiLVjqILF4m4oyQB18W7Ggea7BfqdH/wGMK7dDiMghv/6WG7znWMwUDzJiXow==
semver-regex@^3.1.2:
version "3.1.4"
resolved "https://registry.yarnpkg.com/semver-regex/-/semver-regex-3.1.4.tgz#13053c0d4aa11d070a2f2872b6b1e3ae1e1971b4"
integrity sha512-6IiqeZNgq01qGf0TId0t3NvKzSvUsjcpdEO3AQNeIjR6A2+ckTnQlDpl4qu1bjRv0RzN3FP9hzFmws3lKqRWkA==
"semver@2 || 3 || 4 || 5", semver@^5.5.0, semver@^5.6.0:
version "5.7.2"
resolved "https://registry.yarnpkg.com/semver/-/semver-5.7.2.tgz#48d55db737c3287cd4835e17fa13feace1c41ef8"
@ -8498,11 +8436,6 @@ which-module@^2.0.0:
resolved "https://registry.yarnpkg.com/which-module/-/which-module-2.0.1.tgz#776b1fe35d90aebe99e8ac15eb24093389a4a409"
integrity sha512-iBdZ57RDvnOR9AGBhML2vFZf7h8vmBjhoaZqODJBFWHVtKkDmKuHai3cx5PgVMrX5YDNp27AofYbAwctSS+vhQ==
which-pm-runs@^1.0.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/which-pm-runs/-/which-pm-runs-1.1.0.tgz#35ccf7b1a0fce87bd8b92a478c9d045785d3bf35"
integrity sha512-n1brCuqClxfFfq/Rb0ICg9giSZqCS+pLtccdag6C2HyufBrh3fBOiy9nb6ggRMvWOVH5GrdJskj5iGTZNxd7SA==
which-typed-array@^1.1.11, which-typed-array@^1.1.2:
version "1.1.11"
resolved "https://registry.yarnpkg.com/which-typed-array/-/which-typed-array-1.1.11.tgz#99d691f23c72aab6768680805a271b69761ed61a"