Skip to content

Commit

Permalink
Merge branch 'master' into streamer-approval-cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar authored Dec 20, 2024
2 parents cf2b324 + 7738fd9 commit ff549c9
Show file tree
Hide file tree
Showing 31 changed files with 124 additions and 71 deletions.
2 changes: 1 addition & 1 deletion conf/base.conf
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ security {
enabled = false
url = "http://ip2proxy.lichess.ovh:1929"
}
pwned.url = ""
pwned.range_url = "https://api.pwnedpasswords.com/range/"
hcaptcha = ${hcaptcha}
lame_name_check = true
password.bpass.secret = ${user.password.bpass.secret}
Expand Down
2 changes: 1 addition & 1 deletion modules/security/src/main/Env.scala
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ final class Env(

lazy val ipTrust: IpTrust = wire[IpTrust]

lazy val pwned: Pwned = Pwned(ws, config.pwnedUrl)
lazy val pwned: Pwned = Pwned(ws, config.pwnedRangeUrl)

lazy val proxy2faSetting: SettingStore[Strings] @@ Proxy2faSetting = settingStore[Strings](
"proxy2fa",
Expand Down
12 changes: 6 additions & 6 deletions modules/security/src/main/Pwned.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@ import play.api.libs.ws.DefaultBodyReadables.*
import play.api.libs.ws.JsonBodyReadables.*
import play.api.libs.ws.StandaloneWSClient

// https://github.com/lichess-org/lila-pwned
final class Pwned(ws: StandaloneWSClient, url: String)(using Executor):
final class Pwned(ws: StandaloneWSClient, rangeUrl: String)(using Executor):

def apply(pass: lila.core.security.ClearPassword): Fu[Boolean] =
url.nonEmpty.so(
rangeUrl.nonEmpty.so:
val (prefix, suffix) = pass.value.sha1.hex.toUpperCase.splitAt(5)
val url = s"${rangeUrl}${prefix}"
ws.url(url)
.addQueryStringParameters("sha1" -> pass.value.sha1)
.addHttpHeaders("Add-Padding" -> "true")
.withRequestTimeout(1.second)
.get()
.map:
case res if res.status == 200 =>
(res.body[JsValue] \ "n").asOpt[Int].exists(_ > 0)
res.body[String].contains(suffix)
case res =>
logger.warn(s"Pwnd ${url} ${res.status} ${res.body[String].take(200)}")
false
.monValue: result =>
_.security.pwned.get(result)
)
2 changes: 1 addition & 1 deletion modules/security/src/main/SecurityConfig.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ final private class SecurityConfig(
val hcaptcha: Hcaptcha.Config,
@ConfigName("ip2proxy") val ip2Proxy: Ip2Proxy,
@ConfigName("lame_name_check") val lameNameCheck: LameNameCheck,
@ConfigName("pwned.url") val pwnedUrl: String,
@ConfigName("pwned.range_url") val pwnedRangeUrl: String,
@ConfigName("password.bpass.secret") val passwordBPassSecret: Secret
)

Expand Down
9 changes: 6 additions & 3 deletions modules/shutup/src/main/Dictionary.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ private object Dictionary:
def en = dict("""
(burn|die) in hell
(f++|ph)(u++|e++|a++)c?k(er|r|u|k|t|ing?|ign|en|tard?|face|off?|e?d|)
(f|ph)a++gg?([oi]t|)
(kill|hang|neck) my ?self
[ck]um(shot|)
[ck]unt(ing|)
Expand Down Expand Up @@ -256,9 +255,11 @@ est[úu]pid[ao]
gilipollas
hdp
hijo de (put\w*|per+a)
hijueputa
idiota
imbecil
madre
malparid[ao]
maric[oó]na?
maric[ao]
mierda
Expand All @@ -267,6 +268,7 @@ payas[ao]
pendejo
po(ll|y)a
put[ao]
putica
trampa
trampos[ao]
tu eres put\w*
Expand Down Expand Up @@ -352,11 +354,12 @@ yar+ak kafa(l[iı]|s[iı])
""")

def critical = dict("""
cancer
(die|burn)s? irl
(f|ph)a++gg?([oi]t|)
(go|pl(ea)?[sz]e?) (a?nd)? ?(die|burn|suicide)
(ho?pe|wish) ((yo?)?[uy](r (famil[yi]|m[ou]m|mother))?( and )?)++ (die|burn)s?
(die|burn)s? irl
(kill|hang|neck) ?(yo?)?[uyi]r? ?(self|famil[yi]|m[ou]m|mother)
cancer
gas the
g?kys
get bombed
Expand Down
15 changes: 15 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions translation/dest/activity/ta-IN.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@
<item quantity="one">%s பிளேயரைப் பின்தொடரத் தொடங்கியது</item>
<item quantity="other">%s வீரர்களைப் பின்தொடரத் தொடங்கியது</item>
</plurals>
<plurals name="gainedNbFollowers">
<item quantity="one">%ஒரு புதிய பின்தொடர்பவர் கிடைத்தது</item>
<item quantity="other">%s புதிய பின்தொடர்பவர்களைப் பெற்றார்</item>
</plurals>
<plurals name="hostedNbSimuls">
<item quantity="one">%s ஒரே நேரத்தில் கண்காட்சி நடத்தப்பட்டது</item>
<item quantity="other">%s ஒரே நேரத்தில் கண்காட்சிகள் நடத்தப்பட்டன</item>
Expand Down
21 changes: 0 additions & 21 deletions ui/@types/lichess/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,29 +155,8 @@ interface Events {
off(key: string, cb: (...args: any[]) => void): void;
}

interface Api {
initializeDom: (root?: HTMLElement) => void;
events: Events;
socket: {
subscribeToMoveLatency: () => void;
events: Events;
};
onlineFriends: {
request: () => void;
events: Events;
};
chat: {
post: (text: string) => void;
};
overrides: {
[key: string]: (...args: any[]) => unknown;
};
analysis?: any;
}

interface Window {
site: Site;
lichess: Api;
fipr: Fipr;
i18n: I18n;
$as<T>(cash: Cash): T;
Expand Down
2 changes: 1 addition & 1 deletion ui/analyse/src/ctrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ export default class AnalyseCtrl {
});
pubsub.on('board.change', redraw);
this.persistence?.merge();
window.lichess.analysis = api(this);
(window as any).lichess.analysis = api(this);
}

initialize(data: AnalyseData, merge: boolean): void {
Expand Down
23 changes: 23 additions & 0 deletions ui/api/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "api",
"version": "2.0.0",
"private": true,
"description": "lichess.org browser extension API",
"author": "Thibault Duplessis",
"license": "AGPL-3.0-or-later",
"typings": "api",
"typesVersions": {
"*": {
"*": [
"dist/*"
]
}
},
"exports": {
".": "./src/api.ts",
"./*": "./src/*.ts"
},
"dependencies": {
"common": "workspace:*"
}
}
27 changes: 24 additions & 3 deletions ui/site/src/api.ts → ui/api/src/api.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,34 @@
import type { Pubsub, PubsubCallback, PubsubEvent } from 'common/pubsub';
import { type PubsubCallback, type PubsubEvent, pubsub, initializeDom } from 'common/pubsub';

// #TODO document these somewhere
const publicEvents = ['ply', 'analysis.change', 'chat.resize', 'analysis.closeAll'];
const socketEvents = ['lag', 'close'];
const socketInEvents = ['mlat', 'fen', 'notifications', 'endData'];
const friendsEvents = ['playing', 'stopped_playing', 'onlines', 'enters', 'leaves'];

export const api = (pubsub: Pubsub): Api => ({
initializeDom: (root?: HTMLElement) => pubsub.emit('content-loaded', root),
export interface Api {
initializeDom: (root?: HTMLElement) => void;
events: Events;
socket: {
subscribeToMoveLatency: () => void;
events: Events;
};
onlineFriends: {
request: () => void;
events: Events;
};
chat: {
post: (text: string) => void;
};
overrides: {
[key: string]: (...args: any[]) => unknown;
};
analysis?: any;
}

// this object is available to extensions as window.lichess
export const api: Api = ((window as any).lichess = {
initializeDom,
events: {
on(name: PubsubEvent, cb: PubsubCallback): void {
if (!publicEvents.includes(name)) throw 'This event is not part of the public API';
Expand Down
3 changes: 3 additions & 0 deletions ui/api/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "../tsconfig.base.json"
}
1 change: 1 addition & 0 deletions ui/bits/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"@types/yaireo__tagify": "4.27.0",
"@types/zxcvbn": "^4.4.5",
"@yaireo/tagify": "4.17.9",
"api": "workspace:*",
"canvas-confetti": "^1.9.3",
"chat": "workspace:*",
"chess": "workspace:*",
Expand Down
3 changes: 2 additions & 1 deletion ui/bits/src/bits.challengePage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as xhr from 'common/xhr';
import { wsConnect, wsSend } from 'common/socket';
import { userComplete } from 'common/userComplete';
import { isTouchDevice, isIos } from 'common/device';
import { initializeDom } from 'common/pubsub';

interface ChallengeOpts {
xhrUrl: string;
Expand All @@ -19,7 +20,7 @@ export function initModule(opts: ChallengeOpts): void {
xhr.text(opts.xhrUrl).then(html => {
$(selector).replaceWith($(html).find(selector));
init();
window.lichess.initializeDom($(selector)[0]);
initializeDom($(selector)[0]);
});
},
},
Expand Down
3 changes: 2 additions & 1 deletion ui/bits/src/bits.infiniteScroll.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as xhr from 'common/xhr';
import { spinnerHtml } from 'common/spinner';
import { initializeDom } from 'common/pubsub';

export function initModule(selector: string = '.infinite-scroll'): void {
$(selector).each(function (this: HTMLElement) {
Expand Down Expand Up @@ -36,7 +37,7 @@ function register(el: HTMLElement, selector: string, backoff = 500) {
nav.remove();
$(el).append(($(html).is(selector) ? $(html) : $(html).find(selector)).html());
dedupEntries(el);
window.lichess.initializeDom(el);
initializeDom(el);
setTimeout(() => register(el, selector, backoff * 1.05), backoff); // recursion with backoff
},
e => {
Expand Down
13 changes: 7 additions & 6 deletions ui/bits/src/bits.tvGames.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as xhr from 'common/xhr';
import { pubsub } from 'common/pubsub';
import { pubsub, initializeDom } from 'common/pubsub';
import { api } from 'api';

interface ReplacementResponse {
id: string;
Expand Down Expand Up @@ -28,8 +29,8 @@ const requestReplacementGame = () => {
.json(url.toString())
.then((data: ReplacementResponse) => {
main.find(`.mini-game[href^="/${oldId}"]`).replaceWith(data.html);
if (data.html.includes('mini-game__result')) window.lichess.overrides.tvGamesOnFinish(data.id);
window.lichess.initializeDom();
if (data.html.includes('mini-game__result')) api.overrides.tvGamesOnFinish(data.id);
initializeDom();
})
.then(done, done);
});
Expand All @@ -40,17 +41,17 @@ const done = () => {
requestReplacementGame();
};

window.lichess.overrides.tvGamesOnFinish = (id: string) =>
api.overrides.tvGamesOnFinish = (id: string) =>
setTimeout(() => {
finishedIdQueue.push(id);
requestReplacementGame();
}, 7000); // 7000 matches the rematch wait duration in /modules/tv/main/Tv.scala

site.load.then(() => {
pubsub.on('socket.in.finish', ({ id }) => window.lichess.overrides.tvGamesOnFinish(id));
pubsub.on('socket.in.finish', ({ id }) => api.overrides.tvGamesOnFinish(id));
$('main.tv-games')
.find('.mini-game')
.each((_i, el) => {
if ($(el).find('.mini-game__result').length > 0) window.lichess.overrides.tvGamesOnFinish(getId(el)!);
if ($(el).find('.mini-game__result').length > 0) api.overrides.tvGamesOnFinish(getId(el)!);
});
});
3 changes: 2 additions & 1 deletion ui/bits/src/bits.user.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as xhr from 'common/xhr';
import { makeLinkPopups } from 'common/linkPopup';
import { alert } from 'common/dialog';
import { initializeDom } from 'common/pubsub';

export function initModule(): void {
makeLinkPopups($('.social_links'));
Expand Down Expand Up @@ -47,7 +48,7 @@ export function initModule(): void {
browseTo = (path: string) =>
xhr.text(path).then(html => {
$content.html(html);
window.lichess.initializeDom($content[0]);
initializeDom($content[0]);
history.replaceState({}, '', path);
site.asset.loadEsm('bits.infiniteScroll');
});
Expand Down
1 change: 1 addition & 0 deletions ui/chat/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
".": "./src/chat.ts"
},
"dependencies": {
"api": "workspace:*",
"common": "workspace:*",
"palantir": "workspace:*"
}
Expand Down
3 changes: 2 additions & 1 deletion ui/chat/src/ctrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { prop } from 'common';
import { storage, type LichessStorage } from 'common/storage';
import { pubsub, type PubsubEvent, type PubsubCallback } from 'common/pubsub';
import { alert } from 'common/dialog';
import { api } from 'api';

export default class ChatCtrl {
data: ChatData;
Expand Down Expand Up @@ -102,7 +103,7 @@ export default class ChatCtrl {
alert('Max length: 140 chars. ' + text.length + ' chars used.');
return false;
}
window.lichess.chat.post(text);
api.chat.post(text);
return true;
};

Expand Down
4 changes: 2 additions & 2 deletions ui/chat/src/moderation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type { ModerationCtrl, ModerationOpts, ModerationData, ModerationReason }
import { numberFormat } from 'common/number';
import { userModInfo, flag, timeout } from './xhr';
import type ChatCtrl from './ctrl';
import { pubsub } from 'common/pubsub';
import { pubsub, initializeDom } from 'common/pubsub';
import { confirm } from 'common/dialog';

export function moderationCtrl(opts: ModerationOpts): ModerationCtrl {
Expand Down Expand Up @@ -158,7 +158,7 @@ export function moderationView(ctrl?: ModerationCtrl): VNode[] | undefined {
{
hook: {
insert() {
window.lichess.initializeDom();
initializeDom();
},
},
},
Expand Down
Loading

0 comments on commit ff549c9

Please sign in to comment.