Skip to content

Commit

Permalink
isort + fix create populated post
Browse files Browse the repository at this point in the history
  • Loading branch information
kheina committed Nov 25, 2024
1 parent 2973c6b commit f220fa2
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 21 deletions.
1 change: 1 addition & 0 deletions account/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import Optional

from pydantic import BaseModel


Expand Down
2 changes: 1 addition & 1 deletion authenticator/authenticator.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from shared.exceptions.http_error import BadRequest, Conflict, HttpError, InternalServerError, NotFound, Unauthorized, UnprocessableEntity
from shared.hashing import Hashable
from shared.models import InternalUser
from shared.models.auth import AuthState, KhUser, Scope, TokenMetadata, AuthToken
from shared.models.auth import AuthState, AuthToken, KhUser, Scope, TokenMetadata
from shared.sql import SqlInterface
from shared.timing import timed
from shared.utilities.json import json_stream
Expand Down
6 changes: 3 additions & 3 deletions init.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
import shutil
import time
from dataclasses import dataclass
from os import listdir, remove, environ
from os import environ, listdir, remove
from os.path import isdir, isfile, join
from secrets import token_bytes
from typing import Any, BinaryIO, Optional
from subprocess import PIPE, Popen
from typing import Any, BinaryIO, Optional

import asyncclick as click
import ujson
Expand All @@ -22,8 +22,8 @@
from shared.base64 import b64decode, b64encode
from shared.caching.key_value_store import KeyValueStore
from shared.config.credentials import decryptCredentialFile, fetch
from shared.sql import SqlInterface
from shared.logging import TerminalAgent
from shared.sql import SqlInterface


def isint(value: Any) -> Optional[int] :
Expand Down
2 changes: 1 addition & 1 deletion k8s.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ spec:
spec:
containers:
- name: fuzzly-backend
image: us-central1-docker.pkg.dev/kheinacom/fuzzly-repo/fuzzly-backend@sha256:b88fba9c9b76fa32844de05eac54025d60c5c1be600b04cae45b112f0860ed22
image: us-central1-docker.pkg.dev/kheinacom/fuzzly-repo/fuzzly-backend@sha256:0a4d49e17d86cbfd1fc18ccaf760edc76206130b7d8c054e2f15f3e3036f7031
env:
- name: pod_ip
valueFrom:
Expand Down
2 changes: 1 addition & 1 deletion shared/email.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
from aiohttp import BasicAuth, ClientTimeout
from aiohttp import request as async_request

from .config.constants import environment
from .config.credentials import fetch
from .exceptions.base_error import BaseError
from .logging import getLogger
from .config.constants import environment


_html_template_1 = "<!DOCTYPE html><html lang='en'><head><style>body{height:100%;width:100%;position:absolute;background:#C3C4CE;background-size:cover;background-position:center;}body,html{background:#C3C4CE;position:relative;z-index:-5;margin:0;padding:0;font-family:Bitstream Vera Sans,DejaVu Sans,Arial,Helvetica,sans-serif;}a,form input,form label,.footer span{cursor:pointer;pointer-events:all;text-decoration:none;color:#222222;transition: ease 0.15s;}a:link{color:#222222;}a:visited{color:inherit;}a:hover{color:#F28817!important;opacity:1!important;transition: ease 0.15s;}h1{margin:0 0 25px;}p{margin:0;}#content{display:block;margin:100px auto;width:100%;padding:25px 0;text-align:center;background:#E0E4E8;}#feature{display:block;margin:0 auto;max-width:900px;padding:0;background:#E0E4E8;}.button{display:inline-block;padding:0.5em 1em;margin:25px 25px 0;border:var(--border-size) solid #2D333A;background:#D8D9E0; box-shadow:0 2px 3px 1px #6D718680;border-radius:3px;white-space:nowrap;}.button:hover{box-shadow:0 0 10px 3px #6D7186B3;border-color:#F28817;}.subtext{color:#00000080;margin:25px 0 0;font-size:0.7em;}</style></head>"
Expand Down
49 changes: 34 additions & 15 deletions uploader/uploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -585,47 +585,66 @@ async def _update_privacy(
vote_task: Optional[Task] = None

if old_privacy in UnpublishedPrivacies and privacy not in UnpublishedPrivacies :
query = """
await t.query_async("""
INSERT INTO kheina.public.post_votes
(user_id, post_id, upvote)
VALUES
(%s, %s, %s)
ON CONFLICT DO NOTHING;
""", (
user.user_id,
post_id.int(),
True,
),
)

await t.query_async("""
INSERT INTO kheina.public.post_scores
(post_id, upvotes, downvotes, top, hot, best, controversial)
VALUES
(%s, %s, %s, %s, %s, %s, %s)
ON CONFLICT DO NOTHING;
""", (
post_id.int(),
1,
0,
1,
calc_hot(1, 0, time()),
confidence(1, 1),
calc_cont(1, 0),
),
)

await t.query_async("""
UPDATE kheina.public.posts
SET created = NOW(),
updated = NOW(),
SET created = now(),
updated = now(),
privacy = privacy_to_id(%s)
WHERE posts.uploader = %s
AND posts.post_id = %s;
"""
params = (
user.user_id, post_id.int(), True,
post_id.int(), 1, 0, 1, calc_hot(1, 0, time()), confidence(1, 1), calc_cont(1, 0),
privacy.name, user.user_id, post_id.int(),
""", (
privacy.name,
user.user_id,
post_id.int(),
),
)

vote_task = ensure_future(VoteKVS.put_async(f'{user.user_id}|{post_id}', 1))

else :
query = """
await t.query_async("""
UPDATE kheina.public.posts
SET updated = NOW(),
SET updated = now(),
privacy = privacy_to_id(%s)
WHERE posts.uploader = %s
AND posts.post_id = %s;
"""
params = (
privacy.name, user.user_id, post_id.int(),
""",(
privacy.name,
user.user_id,
post_id.int(),
),
)

await t.query_async(query, params)

try :
tags: list[InternalTag] = await tags_task

Expand Down

0 comments on commit f220fa2

Please sign in to comment.