Skip to content

Commit

Permalink
feat: support update privacy message
Browse files Browse the repository at this point in the history
  • Loading branch information
Yazawazi committed Feb 28, 2024
1 parent 8e15d7d commit f2649a7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
11 changes: 10 additions & 1 deletion backend/funix/app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from pathlib import Path
from secrets import token_hex
from enum import Enum
import hashlib

from flask import Flask, Response, abort, request
from flask_sock import Sock
Expand Down Expand Up @@ -51,12 +52,17 @@ class LogLevel(Enum):
4. Clicking "Agree" indicates that you agree to the above data policy.
"""

privacy_update_hash = hashlib.sha256(
privacy.encode() + str(funix_log_level.value).encode()
).hexdigest()


@app.get("/privacy")
def __funix_privacy():
return {
"text": privacy,
"log_level": int(funix_log_level.value),
"hash": privacy_update_hash,
}


Expand All @@ -70,7 +76,10 @@ def privacy_policy(message: str) -> None:
Returns:
None
"""
global privacy
global privacy, privacy_update_hash
privacy_update_hash = hashlib.sha256(
message.encode() + str(funix_log_level.value).encode()
).hexdigest()
privacy = message


Expand Down
16 changes: 12 additions & 4 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ const App = () => {
const [onResizing, setOnResizing] = useState(false);
const historyLoaded = useRef<boolean>(false);
const [privacyText, setPrivacyText] = useState("");
const [lastPrivacyHash, setLastPrivacyHash] = useState("");

const handlePointerMoveLeftSidebar = useCallback((e: PointerEvent | any) => {
setFunctionListWidth(e.clientX - document.body.offsetLeft);
Expand Down Expand Up @@ -317,13 +318,18 @@ const App = () => {
.then((body) => {
return body.json();
})
.then((json: { text: string; log_level: number }) => {
.then((json: { text: string; log_level: number; hash: string }) => {
setPrivacyText(json.text);
setLogLevel(json.log_level);
setLastPrivacyHash(json.hash);

setPrivacy(
json.log_level === 0 ? false : getCookie("first-join") === undefined
);
if (localStorage.getItem("privacy-hash") !== json.hash) {
setPrivacy(true);
} else {
setPrivacy(
json.log_level === 0 ? false : getCookie("first-join") === undefined
);
}
});

return (
Expand All @@ -341,6 +347,7 @@ const App = () => {
logLevel === 1
? setCookie("DO_NOT_LOG_ME", "YES")
: (window.location.href = "https://funix.io");
localStorage.setItem("privacy-hash", lastPrivacyHash);
setCookie("first-join", "false", { expires: 365 * 10 });
setPrivacy(false);
}}
Expand All @@ -351,6 +358,7 @@ const App = () => {
onClick={() => {
setCookie("first-join", "false", { expires: 365 * 10 });
setPrivacy(false);
localStorage.setItem("privacy-hash", lastPrivacyHash);
}}
>
Agree
Expand Down

0 comments on commit f2649a7

Please sign in to comment.