#development
1 messages · Page 234 of 1
ermmmmm
idfk
😭
I mean I have some page.server.ts files
that handles form submissions to fetch the apis
mainly because superforms requires an action on the server side to handle submissions
and what runs them?
if you're using npm run or node for routing then you're using svelte as a server as well
therefore you can do serverside rendering
which means
page.server.js files are run on the server side
which means, you can directly fetch data from db in there, if a session exists, and add that to the page data
on page load
so you dont need to fetch nor store in localstorage

thats why its confusing
because frontend and backend are distinct things
and svelte can run on both modes
frontend only
or full stack framework
my thing is
like nextjs and shit
my login endpoint returns the user data of the session
what?
if the user is already logged in
then ALL pages can already load with the data already there
embedded in the js/html

I do not follow your thought process at all
I see no reaso nto connect my frontend to my db
ok
i have received a notification from this channel
who dare disturb chloe's thy inner zen
its not that complicated
it depends on what you want to do
if you want a single app layout (you can switch pages without reloads) you just keep your user states and things to persist in your layout
you can import that from any component
but in general you should login in the user, then store their details in local storage
then you can fetch those details at any time
or do things SSR
ys but how
Thats what I am confused on
the way superforms works what im using for form validation is it requires an action on the server via +page.server.ts to handle the resulting values from it
I dont see how I can store something in local storage, from the server
When you receive data from the server on the client side, what’s stopping you from storing it in local storage
You’re wanting to store user information right?
yes
My client submits a form, a server action inside +page.server.ts handles that action, and requests my rust backend api for logging in, which returns the userinformation about that user's session
Well since you’re using super forms, you can return message(form, <custom data>) from the form action and it’ll be under the message form given by the super forms client side thing
Or there’s an onUpdate function you can set in the superforms properties
Form submit
Runs your server side action which does stuff with your other backend
Return whatever response you want to the client
access via the onUpdate or message store and do whatever you want with it
right but how should I return it?
return message(form, {anything})
export const actions = {
default: async ({ request, fetch }) => {
const form = await superValidate(request, zod(loginSchema))
let response = await fetch('/api/auth/login', {
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
method: 'post',
body: new URLSearchParams({
email: form.data.email,
password: form.data.password
})
})
const data = await response.json()
return { form, data }
}
}
```?
You also need to check if your form object is valid
import { superValidate, message } from 'sveltekit-superforms'
import { zod } from 'sveltekit-superforms/adapters'
import type { PageServerLoad } from './$types'
import { loginSchema } from '$lib'
export const load: PageServerLoad = async () => {
const form = await superValidate(zod(loginSchema))
return { form }
}
export const actions = {
default: async ({ request, fetch }) => {
const form = await superValidate(request, zod(loginSchema))
let response = await fetch('/api/auth/login', {
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
method: 'post',
body: new URLSearchParams({
email: form.data.email,
password: form.data.password
})
})
const data = await response.json()
return message(form, { data })
}
}
```?
Yes
Now you should be able to get the data in your client side through either onUpdate or the message store
Yes
Stores aren’t persistent
well yea ik
If you refresh they’re gone
To have reactive data across the entire app
They’re meant for use on a spa
Where it doesn’t refresh on each navigation
There is a package that can use local storage with svelte stores though
what exactly constitues something as an spa?
Uhhhh
I believe it’s when the dom changes with JavaScript instead of it navigating to a different html file
Well personally I’d say local storage isn’t the way to do it bc it could be invalid/out of date data

you just made me even more confused
what the hell was the entire point of this
if you are now telling me its not the best idea

LOL
I mean I’m no professional
But on my sites it’s
Page load
Layout onMount fetches auth data from route
Sets data to a store
Then can update the ui accordingly
im fixing to just sell one of my fucking kidneys and hire a frontend dev
I cant do this anymore

I think having the 2 backends confuses it a lot
I just do not fucking understand
why does a frontend framework
have a backend api
ITS FOR FRONTEND
svelte is the front end
Sveltekit is the framework that works with svelte
it’s like react and nextjs
I don’t even wanna attempt those
I was using nextjs originally
but then I thought "Oh maybe state management is better in svelte"
I was fucking wrong
Why do frontend frameworks have to make everything more complicated than it needs to be
yes you are using sveltekit which provides routing too
you dont have to use it
you can use svelte standalone if you want to
thats how it started out anyways
I mean sure
but then i'd have to setup routing myself
im not hating on sveltekit
Im hating on how I have to do this
Its more complicated than it needs to be
if i replace rust with zig will my build times be faster?
i personally only use sveltekit for the routing
and i agree with that you dont have to use the extended features
you can disable SSR which basically makes sveltekit a router
thats what i did
All I want to do...is just render the person name when they fucking login
thats it

Well the thing is, the form validation library I use, requires a page.server.ts file
to export an action
thats understandable
my issue is
that library is for users that want to integrate backend and frontends together with sveltekit
it defeats the point using it with a different backend
I can't set the state for that user that loggged in on the server or else ANYONE will be able to see that state
I mean fair enough
but I also don't know how to validate forms myself
😔
Just shout at them if they break it
a lot of backend routers have automatic validation for these things
you just define the schema and it verifies the data before it gets passed to your routers
JSON Schema
ill show you how it looks on mine
ok
in this case it expects the data to be:
{ type: either_1_or_2_number, content: string_with_max_length_500, nonce: some_number }
if it isnt it will return a nice detailed error message as response
if everything fits the schema it continues with the handler below and you dont need to worry about validation anymore
theres also libraries which make creating schemas easier
i just wanted to define them manually
and from the front end i just do a fetch request with the data to the backend
like zod?
you can do it with forms too
I use zod for schemas
import * as z from 'zod'
export const schema = z.object({
firstName: z.string().min(1, "is invalid"),
lastName: z.string().min(1, "is invalid"),
email: z.string().email("is invalid"),
password: z.string().min(8, "minimum 8 characters"),
passwordConfirmation: z.string()
}).required().refine((data) => data.password === data.passwordConfirmation, {
message: 'doesn\'t match',
path: ['passwordConfirmation']
})
export const loginSchema = z.object({
email: z.string().email("is invalid"),
password: z.string().min(8, "minimum 8 characters")
}).required()
that works too
the backend will verify the incoming data
and if anything goes wrong add a handler for the frontend form error
so you can display an error or whatever
hm
I thought the entire point of client-side validation errors, was to mitigate problems before they start
why delgate ALL the work to the backend?
sure the backend should still check
Authority is the main concern. People can easily forget if they assume the client will do all the heavy lifting
you should do client-side validation too but youd have to do them separate
its quite easy to add for forms
client side validation is only useful if you want to avoid unnecessary traffic
Such as in cases of rate limits
Depending on how complex the inner logic of the validation is, it could just be free basically
you have to validate the incoming data anyways because otherwise an attacker can exploit that
well yes
I wasn't saying not to
I was wondering why put all the heavy lifting on the backend
ofc someone can decide to manually hit it without the form so you should do validations server side as well
a lot of people do it because its easier and it doesnt really affect the server all that much when it comes to traffic
but you should do client side verification too to provide instant feedback and not request server unnecessarily
but if you do or dont its not a big deal
SSR?
Server Side Rendering ig is what you guys call it
Better for SEO and quicker than client side rendering
You need to do some SSR for stuff like X Site Request Forgery tokens
so you can't disable it outright?
You shouldnt for forms or any actions that create/modify/delete data
xsrf is really important to defend against
thats a big use for SSR but you can also do without really
modern browsers have a lot of security headers and prevention measures you can use now instead
or by being smart with how you construct your app and api calls
🤐 That's an L excuse since older browsers still exist. More security holes
you can, i have
if youre using an outdated browser thats on you
I cant guard your stupidity
The US government still uses an older Windows version because modern ones are less stable
ima be real
But whatever. You problem to solve
who cares about the us gov
if they are using my app on their systems, then they are already done for
they pay microsoft for extended security updates so microsoft still maintains these versions and keeps them secure
Also, if we are to believe those iso leaks for the gov edition of windows, then they have virtually nothing on them anyway, and while it may have been for the chinese gov, the US definitely emplores similar conditions
cant even get a browser on it
I think the main thing is getting used to the workflow when you branch out to other endeavors unrelated to what you're working on and is meant to be more widely adopted. Will you allow your laziness to prevent you from guarding against shit like that or will you get serious. Even if you do get serious, more research
it takes too much time maintaining support for older software which means less time to focus on things that matter
the ones that run outdated versions of operating systems usually arent public facing anyways
you wouldnt be able to access them from the outside
itd be too much of a risk even with security updates doing that with front facing servers
im not sure though since i havent worked on government related projects
you need to get top security clearance to touch any government resources and i didnt bother with it really
some colleagues did though but well cant tell me
what does on:submit return
I looked at the interweb and it tells me a EventHandler<HTMLFormEvent> or smth
You can access the form data using the event
im trying
but since im using ts
the param takes a type
idk what type to give it
yes
let email = '';
let password = '';
let errors = writable<{ email: string; password: string }>({ email: '', password: '' });
function onSubmit() {}
and then I bind my inputs bind:value={email} bind:value={password}
and then I do on:submit={onSubmit}
I really dk what im doing
😔
use SubmitEvent as type
youre welcome
although the event itself doesnt give you too much info
how does bind:value work
does it set the value once they click out of it
or is it as they are typing?
because if I can just bind the value to a variable
yes it attaches the value of the input to the variable
I can just not listen to any event specific parameters
so if you change the value of the variable in js it will change the input too
and if the user changes it too
and just post using email password variables
true web devers bind the form inputs to variables so you have quick reactive access to them
although if you dont need them to be reactive you dont have to
you can just get the values when the form submits
const formData = new FormData(e.target);
const formProps = Object.fromEntries(formData);
formProps gives you an object of all of the values in the form
make sure to do |preventdefault too otherwise it will submit the form
isnt that what I want tho?
idk youre doing a custom onsubmit event so i figured that you werent
otherwise if you want the form to automatically subimt the data to the server you wouldnt
how do they submit the form otherwise?
<form method="post" enctype="application/x-www-form-urlencoded">
although be warned the data that is sent isnt json
its form urlencoded
you can parse that on the server too though with middleware
if you want json you have to go the custom route
ah my backend handles form submissions
:D
It has an extractor for x-www-form-urlencoded type data
also using method="post" with svelte kit seems to not work
if you dont have an action going with it
I also have no need I think as I will be submitting the values manually via onSubmit
my question was if preventDefault prevents the form from fully submitting
then wont that cause issues?
if you dont include it, the browser will submit the form in its default way
which will probably mess up your page
ic
I understand that
My question is, what do I do when its time to submit the form, or is there no need to let it do its thing and simply just redirect them when login is done
if you want to send the data to the server manually you dont need the form to submit itself anymore since youre handling that yourself
you will still get the submit event though which will let you know that the user clicked "login" or whatever
in your js youd get the form data and send it to the server somehow
then redirect the user ig
hence the name preventDefault
I can't get FormData from the target
why not
lies
your form must not be done properly
all of your inputs are inside the form and have names?
unless you see something im not
yes
function onSubmit(event: SubmitEvent) {
const formData = new FormData(event.target as HTMLFormElement);
console.log(formData);
const formProps = Object.entries(formData);
console.log(formProps);
}
console.log([...formData.entries()])
or console.log([...formData])
formData is a very weird class, all its properties are hidden, the object itself is always empty
the only way to access the data is by using its built in iterator
interesting, it returns it as a key,value string
separated by ,
ye
Error: Function called outside component initialization
bro wtf is this
😭
telling me to use onMount
but how tf am I going to do that when the function takes in params
He
So wait, I have a question
On login, should I store it in localstorage (so it persists on restarts) or in a store or both?
and if both, how do I repopualte the store on say restarts
and if only in localstorage, how do I handle retreiving the data efficiently because fetching from localstorage each time someone refreshes the page seems inefficient
i mean
from the looks of it
youre using svelte as a fullstack framework
so you're using SSR
I actually stopped using superforms which requires a .server.ts file
and do the validation in the page.svelte file
lets see if i can explain correctly
like
you have two ways of working, generally
-
SSR (server side rendering):
browser requests page
server receives request
server processes sessions and states
server renders/generates page (components are processed, stores are loaded and populated, data resolved and is inserted into the page)
server emits/sends raw pre-built html+css+js to browser (which already includes the data inside the html)
browser displays page -
CSR (client side rendering):
browser requests page
server receives request
server sends raw html+css+js files
browser begins loading page
browser runs functions (fetch, localstorage) and updates page accordingly
browser displays page
why did I think frontend would be a cool hip thing to try
I am regretting my decision
with SSR you dont really need localstorage nor fetch
its like php
on every page request, your server runs serverside things and injects data into the html
with CSR you have to fetch stuff and store in localstorage otherwise you lose data when you navigate to a different page
on login you generate session cookie, on every page load your serverside js files check for session and add data to components
so essentially, you use svelte stores to hold user data only if a session exists
I already have a login endpoint that returns user data
and I have an endpoint that can be fetched if need be to get that user data based on the session
Right
Here's the thing
I've been trying for what, 8 hours now
and I can't get stores to work
It just wont set the user data in the store
I have no fucking clue what im doing wrong
Also for SSR to be a thing, don't I need to use +page.server.ts files?
i have never done this myself before, but im pretty sure what you need is contexts
(scroll down to context)
Im using context

https://pastes.dev/ZAC22xis8W my entire login page and then on my main layout page I getContext('user') and its null
you're missing the cookie handling
wdym
because thats how you check if a user is logged in or not
my login endpoint sets a cookie for the session and returns the user data based on that session?

I am confused
why does my frontend need to get something that is already set
any page in your website, ie /home, needs to check if a session exists or not
right
but
isn't that the entire point of stores
its going to be empty if they aren't logged in
so why do I need to check for a cookie
because thats where the session is stored
but all the cookie gives me is some random id assigned by the backend
its usless on its own unless you are requesting protected routes
correct
im not sure I follow your thought process
The backend does all the checks
If the frontend is fetching a protected route ON the backend, and they aren't logged in, it responds as such
user visits page (not logged in)
page checks for cookie (does not exist)
page renders non-logged in
user logs in via form
form posts login data
server saves session cookie
user is redirected
user visits page (logged in)
page checks for cookie (does exist)
page renders login-only stuff
ok
but
question
Is the entire point of stores usless then?
If a store is empty that EQUALS them not being logged in
stores and contexts are for handling data between svelte components
when a user visits a page, svelte generates the page by running the components and building the page
the components create stores and contexts for other components and child components to know whats going on and render accordingly
once the page is done and sent to the browser, everything is gone
when the user visits another page, the entire component process is started again, stores and contexts are created so that child components know whats going on, etc
of course svelte caches a big part of this process
so that when a user visits a different page, most of the component stuff is already pre-rendered
Ok
svelte store is not a real persistent storage, its created and destroyed on every page visit
because they hate themselves
check out alpine.js
So wait, I have a question. Lets assume I was using svelte's built in stores, context and cookies
- User logs in
- Server sets a cookie
- User redirected to home page
- Main layout checks cookies to see if they are logged in
- If so, grab the user data from an endpoint and return it to the client
- Inside the layout, grab that data, set it in a store and then in context
The only reason I say check cookies in the main layout, is because if they are logged in, the navbar will reflect that, so it seems like the most obviously place to check this and set if they are or aren't
I might be misunderstanding your explanation though
Because im not exactly 100% sure on where I should check if they are logged in or not, without doing so on EVERY single page that requests data from a protected backend endpoint
which idk about you seems inefficient
Although I will note, if someone requests data from a protected endpoint and they aren't logged in, my middleware on the backend automatically redirects them to the login page
so if they try and access say
example.com/dashboard and dashboard frontend route requests data from the backend, and is a protected route. if they aren't logged in, my backend will be like "Hey go here instead"
correct, except that step 5 is not yet sending data to the client
step 6 happens inside the server still
what
but the svelte devs themselves said NEVER set data in stores inside the server side
Lest you want bill to see sally's data
lol wut
checking the cookie and setting up the store with the user data happens on the server side

then the components are rendered and the layout drawn based on that data
This is why I dont fucking ask for help in framework specific servers
they lied to me
I showed them how i was doing it before, which was setting the user data on the server side
and they were like "no no no, you are sharing that with everyone"
😔
😔
Right
but im still confused on the cookie thing
or wait
Since I am redirecting them back to the home page I can check the cookie in
+layout.server.ts which will be able to see if the cookie exists aka if they truly did login, or just visited
if they do have a cookie, set user data
if not, cool go about your day but you can't visit any protected pages
My only question is, I obv don't want to send useless requests to the server if I know they aren't logged in, so how do I render the page as being 403 (Unauthorized) without fetching server backend first to check
if the cookie doesnt exist, they are not logged in
so you can ismply check for the cookie, and if it doesnt exist, directly render an html component with a big 403 text
facts
Right I fucking give up
I cannot for the life of me, get these fucking stores to work properly
about cookies thingy?
No
not even that
I have all that
It wont set the fucking data in the store
its like I ask it to, but then its like "nope, I dont wanna"
time to use window.localStorage.setItem("", "") 
where are you setting the stores
it can be a bit unintuitive at first because of how sveltekit kinda blurs client and server
oh sveltekit is just like nextjs?
I am setting them server-side
in a ts file that has a function called validateUser (which fetches an endpoint for user information while checking they have a cookie) and then calling this function inside hooks.server.ts
import type { Cookies } from "@sveltejs/kit";
import { userStore, type User } from "./user";
export async function validateUser(cookies: Cookies): Promise<User | null> {
let session_id = cookies.get('id');
if (!session_id) return null;
let response = await fetch('api/users/@me');
console.log(response)
let userData = await response.json();
userStore.set(userData)
return userData;
}
import { validateUser } from "$lib";
import { redirect, type Handle } from "@sveltejs/kit";
export const handle: Handle = async ({ event, resolve }) => {
event.locals.user = await validateUser(event.cookies);
if (event.url.pathname.startsWith('/app')) {
const fromUrl = event.url.pathname + event.url.search;
console.log('Hello')
if (!event.locals.user) {
throw redirect(303, `/login?redirectTo=${fromUrl}`)
}
}
// Stage 1
const response = resolve(event)
return response
}
im also setting the userdata in event.locals so I can use it in server-side components without fetching from store
also i notice I can't do /api/users@/me
apparently its not recognizable despite the api running on the same domain proxied with nginx
hm, wait it seems I can't use stores on the server
so wtf am I supposed to do

yeah they're global
since they're actually stored on the server
are you just trying to pass data between the client and the server?
What im trying to do is store the user data when they login so I can use it to display on the client side, or even make future requests for more detailed data
imma keep it real i have like a very similar issue and i just gave up and moved on cause i'm too lazy to figure out an elegant way to pass data
like obviously there is i'm just missing something
it's so over sveltebros
Im
like
so annoyed
because frontend is the only thing stopping me rn
I can code the backend in a giffy if I really wanted to, for the past 3 days i've been trying to figure out how to log people in and display the data
@scenic kelp right so the responses from the svelte devs
use hooks to set event.locals.whatever then inside your page.server.ts file load functions returns something like
export const load = ({ locals }) => {
return {
whatever: locals.whatever
}
}
and in your component use $page.data
apparently thats how you are supposed to do it
oh right
but its not reactive
so idfk what you are supposed to do if they say change their name
you can use a store on the client side though
How would that work?
do you just rely on $page.data.whatever not being null or smth
ig you can make it nullable
and just allow your store to also be nullable
can i pass something to discordSecretMiddleware ?
func discordSecretMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// my code
})
}
func smth(router bla, db bla, rest bla) {
router.Use(discordSecretMiddleware)
}
i want to pass the db and rest to discordSecretMiddleware
yep
so
you can quite literally
func something(yourParams) http.Handler {
return func discordSecretMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// my code
})
}
}
and just use something as the middleware
:)
its a deeper callstack
so careful
idk how go handles function callstack
esspecially since HandlerFunc takes in a func
💀
it's fine ig
need some tweaking
func createDiscordSecretMiddleware(cassandraService *services.CassandraService, service *services.RestService) func(http.Handler) http.Handler {
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// my codes
})
}
}
thanks!

No problem
https://stackoverflow.com/questions/61069784/how-to-pass-a-parameter-to-a-middlewarefunc thank this post

thank for searching that for me 
can bots have an animated profile pic?
so it’ll only show animated when you tap on the bots profile i’m guessing?
that's normal
is there any bot devs that can make me a custom bot?
what kind of bot are you wanting?
dm ill explain
idk if its classed as simple cus ive never made a bot before
this channel specifically is for developing bots by the way
We don't create commissioned bots here, we help when someone creates their bot
i need a bot that can make a code for a user when they join and then a verify command to check who the codes belong to ect
oh damn
we can help you develop one but there are verification bots already created that you can use
i cant make one lol idk anything abt coding
Then it's a good time to learn. The problem with creating bots on Discord is not writing it, but firstly hosting it + maintaining it because, for example, discord.js likes to make changes to its library quite often
you can if you dedicated yourself to learn! i just started not too long ago. @deft wolf will tell you. i came here not knowing the first thing about coding, dedicated myself to learn and although i still have lots to learn, this community has really helped me a lot.
If your bot stopped working, you would have to look for someone to fix it for you again
now i have my own fully custom bot and i created a game bot that’s in several servers and still getting requests to add it to their server!
ali cabbar is bot owner
im a busy guy tho aint got time to learn it lol
Learning would save you money because you will either have to hire a developer for a longer period of time or pay every time you need a developer to fix some error in the bot + add something to it
all about dedication lol
true
Doesn’t take a lot of effort to learn the basics actually
There’s a ton to learn but you can start very quickly
wdym
Your progress has been insane.
^
thats understandable
I'm not sure what you're looking for exactly.
Just assign a code to a user when they join? and looking up a user via that code?
Is that all it needs?
If thats all it needs, does it need to be unique to a server?
im gonna have a few hundred users tho
so its not easy to type all that lmao
If it doesn't need to be unique to the server, you can just use userIDs.
Discord already assigns a unique "code" to each user across all servers.
-ui 136583532972605440
136583532972605440 would be mine
I could not be in the server and that ID would still be searchable through discord.
https://www.fiverr.com/ Devs on fiverr could probably make what you need for $30-$50 either way.
topgg should make a place for people to post advertisements for devs since im sure there are a lot here that would be interested
I feel like people ask for help here a few times a week looking for a dev.
Anyone could send this person a DM and make an offer
(If someone does make an offer, make sure they understand they will be paying server fees)
then again a lot of people asking here for devs dont have the budget for it and dont know how much developers tend to charge
come with a $20 budget
some devs would be happy to do that but it becomes a bit messy
but you shouldnt expect a quality bot
Yeah.
- Make me a bot like Dyno
- How much are you willing to pay?
- You will get a role on my Discord server
Even my fee would probably start at $100 if they dont want to use discords userIDs.
Just for the extremely simple feature set that's been mentioned.
Assuming I'd have to rent the server, setup the server.
Then the monthly server costs
Looking for a dev for one page frontend for a restaurant's menu
You seem to be asking for something you don't have experience for or something that hasn't been done yet, but really need for your bot/server.
You can hire developers from Fiverr or Freelancer to code the things you need for your bot/server.
(or for websites)
young sheldon the beloved
how to do that in markdown
span
markdown allows html too
i dont wanna use tables on this case
im making this for dummies, some people cant read tables and translatre that to a string parameter
:^)
well, it's fine then, tho the underline is a bit out of place
feels cleaner yeah
u can use span to color the params if u want to make it clear that it's separate from the description
but that's separate enough tbh
ye ill just leave it like that then
see this is how i waste my time, doing bulshit microdesigning that nobody cares about instead of actualyl coding
:^)
noooooo
what am i gonna do now
#broke
im thinking about creating a download page for my tauri app
any tips on how i could approach this?
(release assets look like this)
what about fetching all assets and like
macos.arm = github.com...aarch64.dmg
macos.x64 = github.com...x64.dmg
you can match the browser's user agent and stuff to detect the user's OS
and have the download page show the link for their OS
did you put a space after \?
@rustic scarab
well you buildscript is shitting itself
or perhaps a parser issue, did you try smth else to edit that file?
oh my fucking god
Welcome to GitHub's home for real-time and historical data on system performance.
i was like
why tf
is coolify not working
but no shit
how can i address race condition issues?
depends on the condition
as there are many ways to solve it
in my click war game, some players keep saying they are getting “interaction failed” and are being eliminated for not getting their response collected, i don’t get any errors and i even added logging to see how many are actually being collected. idk if these people are lying or not but the only thing i can think that would cause that is maybe they are tapping the same button at the exact same time? idk im stuck
this particular game had 100 people in it
can you send the code again?
yes give me about 15 mins
what is a click war game?
ah, I think I kinda understand what it is supposed to be
they have to click asap right? it's possible you're being ratelimited
by your description it can't be a race condition, js is single-threaded and user network delay would be big enough to allow plenty of space between clicks
I'd advise against any reaction-based games, as it'll be very biased towards users with better connection, and your own bot's latency could heavily affect the outcome of the game
ive decided to make my mysql wrapper a standalone project people can use... there seems to be a lack of good lightweight mysql wrappers that do things properly and offer both an async interface AND prepared statments
https://github.com/brainboxdotcc/dpp-mysql
Yeah?
would the rate limit be based on the amount of players?
rate limits do not apply for interaction responses afaik
each person sees their own button, which generates its own token
hm. so i guess it just boils down to either my internet connection or the players internet connection?
or discord API lags a bit with that many players?
what are your thoughts? @quartz kindle
are the oplayers seeing "interaction failed" or "interaction did not respond"?
they are reporting “interaction failed”
and you dont see any error on your end right?
correct
for those users that failed, do you see their id in your logs?
this one specifically
console.log(`Collected interaction: ${i.customId} from ${i.user.id}`);
i’d have to try and get another big game going and have players screenshot their interaction failed and look
alright
time to use an eslint plugin that hasnt been updated since
in any case, there is a chance its discord's fault, or the user having an outdated discord app
but strictly from your code's perspective, there are some things that can be improved in regards to timings
👀
but i dont see any major point of failure
please can i have some tips? i hear you’re the king of optimizing
the main issue with your code is that you have two timings happening at the same time, the game round time and the interaction collection time
and those timings are independent from each other, which they shouldnt be
this by itself does not cause a direct issue, but can cause weird behavior in case of blocking and major lags
so my suggestion is
- get rid of the while loop and make the function recursive (or make a separate function)
- on collector end, wait 2 seconds, then call the game function again
for example:
rungame() -> create collector -> handle interactions -> on collector end -> wait some delay -> rungame() again
this way you have more control of the timing, and if some major lag happens, there is no chance of the next round being run too soon
other than that, take note of the ids of people who have that problem, and see if you receive events from them at all or not
might be an issue with their app, or discord itself
do you send any message to tell them they clicked?
ah nvm
there are a lot of other things i would personally do differently, but it wouldn't change much for the end result
there is a lot in that code that can be simplified, the whole thing can be much smaller / fewer lines of code
hello king of optimizing
might sa well change your nick to that
JS Optimizer
opTIMizing
lmao
oh tim
I got the login thing to work
:D
it uses the built in page store
and because of that, every page will have access to it
:p
cool
@shell tundra
ffs
weekly prune!
probably their unneeded homework files
damn
npm cache for one project is a more reasonable assumption
only if you use react
#shotsfired
lmfao
a big chunk of node_modules is dev deps
eslint, ts, etc
those are stupid large and serve zero purpose on runtime
lets see ewhat the current size of my target folder is :)
always omit dev in production
rusty
3,9G for debug builds
a release binary is also like 8x less
14x*
debug has 0 optimizations and just builds your code as is though, so release throws out what it doesn't need and keep what it does
Miauw miauw
i love linux
literally haven't tpuched this VM for like 3 months
can't ssh in
client_loop: send disconnect: Broken pipe
Hey bun you use vidstack right?
@scenic kelp im bout to explode bro
I swear
I have no idea if its my css, or svelte itself, but the video player I am trying to make is not showing up 
Just tried the same setup on react and it shows up fine

code issue
well idk
the media player is originally for react
it might be a bug in the svelte port
so pro
ez

the struggles of trying to make next/image work
what's the difference between next/image and normal <image/>
optimization
ooo
if u have a 1920x1080 image but it shows on the site as e.g. 480x270, it'll resize to ~480x270 on the server
Is guild.me a still valid property?
depends on that library you are using
In djs its now guild.members.me
Thank you, is it possible to provide an array into permissions.has()?
Instead of using lots of .has() functions
The example shows that it is possible
https://discordjs.guide/popular-topics/permissions.html#checking-for-permissions
Thank you
Whats up?
I need to know how to load user data from an endpoint on initial load (e.g when they visit the site for the first time) and also protect my pages
My backend api written in rust handles creating the session and setting the cookie
My frontend just needs to
- Login & Redirect back to home page
- Display the data fetched from /users/@me (which also gets stored in state using zustand (which just uses context and state) )
in svelte I could do https://hatebin.com/lmdybyosca
which was placed in a +layout.server.ts which the load function gets ran only once
So you already have the login? you just need the state part?
yes
my login endpoint returns no data because it makes no sense to save state then and there
as if they leave the page it goes away
I need to be able to load state when they visit the website
is this a fair way of doing this or is there a better method
guess there is using regex but it's not much of a difference as the regex has to be hardcoded as well, nvm!
The way you've described it I dont think I've ever done before.
Unless you're looking for it to only happen once per page load, not once overall.
I mean i'd like not to spam my api for requests of data that I already have

Assuming its just username and avatar and basic non private information I'd just chuck it in localstorage.
hm
If its a secured page you'll want to fetch the session information every page load though.
I wish the media player I was using worked with svelte
this is more annoying than anything

If your backend is reasonably fast you should be able to handle thousands of /user/me requests a second even on extremely basic hardware.
It feels like this is pre-optimizing for something you wont need to worry about for years.
this isn't for some bot though
this is for a site that is meant to be heavily trafficed
So thousands could turn into hundreds of thousands a second
I mean, top.gg sends session data all the time.
maybe it doesnt anymore 👀
It still sends every page visit
just use fast db™️
well, assuming the login/logout system is all in one place session data can reasonably be cached in the backend. As long as that cache is properly invalidated whenever someone updates their profile or logs out.
But thats mico-optimizing.
I wouldnt worry about that until later.
i have been trying to get http3 work on my nginx since like last year, spent tons of hours trying every single config and it never worked
today i found out why
port 443 UDP was blocked on the hetzner firewall
@_@
lmaoo 😭
for some reason it still fails the domsignal test, but it passes http3check test and shows up as h3 on network tab from second load onwards
hetzner clearly isnt a fan of quic
galaxygate has literally no firewall as far as i know
you have to set one up yourself with ufw
thats a deathtrap for people new to managing servers
very easy to accidentally expose internal ports
I mean skill issue for binding internal things to public interfaces
@quartz kindle why are b trees more commonly used for database indexing
at least i think they are
b+ trees are way better suited for databases
since you can easily do range queries
just need to traverse down the tree between 2 ranges and select all the leaf nodes in between
no idea
im pretty sure most dbs support both
and lets you chose
B+ trees are way better for sure and iirc most databases are preferring b+ trees.
Though, I think that the main reason why b trees are still largely in use is cuz b trees have a simpler structure hence they are less memory intensive.
They also tend to store data directly in the parent node instead of leaf node which can lead to 1 less traversal per query.
yeah probably
the internal nodes dont store any data so they essentially just take up space
as opposed to b trees where they also store data
and it doesnt matter if you find the key in the internal node you still have to traverse down to the leaf node
for simpler database structures and query types b trees seem to have more benefits
for more complex queries like ranges you should use b+ trees
as with everything in life theres a trade off between the two
I had to leave svelte behind Chloe
svelte doesnt miss non believers
thats like switching your entire programming language mid development because a library doesnt work
uhm
yea if you can't continue the project without it
💀
I quite literally needed that library to continue my development
There was no other alternative
Make your own duh
uhm sureeee
Ima make my own media player from scratch that supports hls streaming, accessiblity, state management (to keep track of where they were, and are) and many other things a media player needs to do by myself
because thats more reasonable

Yes you are so right
Also
I just found out reacts way to do it
I have to load the data server side, pass it along to the client side via a component, and then store it in context
💀
React just seems infinitely more complex than svelte
I mean its not really much different from svelte, except I could load it in the server and return it, and have access to it immediately via page store
Well if you know of any media player library, or know how to get vidstack.io to work on svelte call me up
until then
im stuck with react as vidstack was made for react first and 100% works
Their website says it works seamlessly with svelte
I assume you followed their get started thing too
yea
considering the platform youre making you should anyways
its not too bad anyways
quite a fun project
you start with a video/source element https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Client-side_web_APIs/Video_and_audio_APIs
I think we've taught you enough in this article. The HTMLMediaElement API makes a wealth of functionality available for creating simple video and audio players, and that's only the tip of the iceberg. See the "See also" section below for links to more complex and interesting functionality.
this is where your video will play since it is hardware accelerated by the browser
you can then hide the default controls and panels and make your own with html+css
will this embed directly into the page?
you can then control pausing, resuming, loading chunks of the video player using javascript
or will it appear "popped out"
my biggest concern is buffering
it will embed
its any other element
the video player will generally handle buffering
you just need to focus on getting the chunks to the video player
I thought buffering was something I had to do
the browser makes it very easy
Which was why I was going to use an already made video player
you can either stream the entire file over and the video element will detect that
or you can send the video with chunks which is much faster and efficient and the element will detect that
no javascript code needed only server side
it will also ask for the relevant chunks if you decide to seek manually in the player
this is a good example someone made https://github.com/DulalSandip/Video-Buffering-and-Streaming-in-Chunk-Size
very simple
the only frontend code thats needed to do buffering and chunking
not a problem
you just do the streaming from the server differently
in the request for chunks the browser will ask you for the next chunks and its position
and you can provide those depending on what you do
if the video element doesnt support your format you can probably convert it to mp4 or something else on the fly

there's also https://www.npmjs.com/package/hls.js
Which makes it easier to stream hls playlists in the browser
Right well thanks :) I have my work cut out for me, but honestly it should be fun :D
Had I know it'd be this easy to get started I would of done it earlier
My biggest concern will be keeping track of where they are in the video in case they come back to it later but I can implement those finer details as I go and work on the project
That shouldn't be too bad though, especially if you are okay with being like 1-2 seconds off
Thats a fun one.
Just an implementation of auto save basically
I did this awhile back.
https://i.woo.pics/41ad639808.mp4
It would get the current frame of the video, and figure out what part of the game they were in. Then map that frame to whatever relevant data is going on in the game.
That was a fun project
There's probably a better way, like using websockets and detecting disconnecting and then making it save on disconnect or something
That's really cool
For a joke project I spent way too much time on it.
Might be useful for a layer project though
wanna come work for me /j
I'm too expensive! 😉
shoot, im $3

Fuck I need to make 3$
well
now that I have the motivation to make my own media player
svelte is back on the table (thank god)
state in react is so fucking annoying
Something like this hooked to an API type situation so you could map it with any data easily would be cool
It defeats the entire purpose of state
Real
It was using the riot api.
But yeah, I could see that
I will likely store placemnet in a video in my db
so that way they can watch multiple videos and if they decide to leave in the middle of em they can pick up where they left off
Like YouTube but then you could map the data custom for things like that^ being easy
just like some "Store x time they were at in a table"




