6 Commits

Author SHA1 Message Date
Daniel Svitan
c4f2006e8f 💚 Renames CI build file
Some checks failed
Gitea Build Action / build-go (push) Successful in 27s
Gitea Build Action / build-nuxt (push) Failing after 6s
2025-06-05 10:04:48 +02:00
Daniel Svitan
7b50441da2 💚 Adds CI build for web 2025-06-05 10:04:29 +02:00
Daniel Svitan
940f6ea1b5 🔧 Adds CORS
All checks were successful
Gitea Build Action / build (push) Successful in 25s
2025-06-05 09:53:46 +02:00
Daniel Svitan
a48d1238a2 🚧 Adds token form
All checks were successful
Gitea Build Action / build (push) Successful in 28s
2025-06-05 09:48:58 +02:00
Daniel Svitan
7aaa0c0aab 💄 Adds actual favicon
All checks were successful
Gitea Build Action / build (push) Successful in 26s
2025-06-04 21:47:55 +02:00
Daniel Svitan
00bf392931 🎉 Inits web
All checks were successful
Gitea Build Action / build (push) Successful in 36s
2025-06-04 21:38:24 +02:00
18 changed files with 2228 additions and 3 deletions

View File

@@ -3,7 +3,7 @@ run-name: ${{ gitea.actor }} build
on: [push]
jobs:
build:
build-go:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
@@ -21,3 +21,17 @@ jobs:
run: cd admin && go get .
- name: "[admin] Build"
run: cd admin && go build -v ./...
build-nuxt:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Bun 1.2.0
run: oven-sh/setup-bun@v2
with:
bun-version: 1.2.0
- name: Display Bun version
run: bun --version
- name: "[web] Install dependencies"
run: cd web && bun install
- name: "[web] Build"
run: cd web && bun run build

BIN
door.xcf Normal file

Binary file not shown.

View File

@@ -105,20 +105,28 @@ class App:
except Exception as e:
print(f"Error occurred: {e}")
def measure_distance(self):
def measure_distance(self) -> float:
self.trigger.low()
utime.sleep_us(2)
self.trigger.high()
utime.sleep_us(10)
self.trigger.low()
start_time = utime.ticks_us()
sent_time = utime.ticks_us()
while self.echo.value() == 0:
print("hey", end="\r")
sent_time = utime.ticks_us()
if sent_time - start_time >= 100_000: # if it takes more than 100ms, stop
return -1
start_time = utime.ticks_us()
received_time = utime.ticks_us()
while self.echo.value() == 1:
print("ho", end="\r")
received_time = utime.ticks_us()
if received_time - start_time >= 100_000: # same
return -1
delta_time = received_time - sent_time
distance = delta_time / 1_000_000 * SOUND_SPEED / 2
@@ -170,5 +178,6 @@ class App:
i += 1
if __name__ == "__main__":
App().run()

View File

@@ -73,6 +73,10 @@ func main() {
LogLevel: log.ERROR,
}))
app.Use(middleware.Secure())
app.Use(middleware.CORSWithConfig(middleware.CORSConfig{
AllowOrigins: []string{"*"},
AllowHeaders: []string{echo.HeaderOrigin, echo.HeaderContentType, echo.HeaderAccept, echo.HeaderAuthorization},
}))
app.Use(middleware.LoggerWithConfig(middleware.LoggerConfig{
Format: "${time_custom} ${method} ${uri} ---> ${status} in ${latency_human} (${bytes_out} bytes)\n",
@@ -213,7 +217,8 @@ func main() {
func authed(next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error {
if c.Request().Header.Get("Authorization") != token {
provided := c.Request().Header.Get("Authorization")
if provided != fmt.Sprintf("Bearer %s", token) {
return c.NoContent(http.StatusUnauthorized)
}

24
web/.gitignore vendored Normal file
View File

@@ -0,0 +1,24 @@
# Nuxt dev/build outputs
.output
.data
.nuxt
.nitro
.cache
dist
# Node dependencies
node_modules
# Logs
logs
*.log
# Misc
.DS_Store
.fleet
.idea
# Local env files
.env
.env.*
!.env.example

75
web/README.md Normal file
View File

@@ -0,0 +1,75 @@
# Nuxt Minimal Starter
Look at the [Nuxt documentation](https://nuxt.com/docs/getting-started/introduction) to learn more.
## Setup
Make sure to install dependencies:
```bash
# npm
npm install
# pnpm
pnpm install
# yarn
yarn install
# bun
bun install
```
## Development Server
Start the development server on `http://localhost:3000`:
```bash
# npm
npm run dev
# pnpm
pnpm dev
# yarn
yarn dev
# bun
bun run dev
```
## Production
Build the application for production:
```bash
# npm
npm run build
# pnpm
pnpm build
# yarn
yarn build
# bun
bun run build
```
Locally preview production build:
```bash
# npm
npm run preview
# pnpm
pnpm preview
# yarn
yarn preview
# bun
bun run preview
```
Check out the [deployment documentation](https://nuxt.com/docs/getting-started/deployment) for more information.

9
web/app.vue Normal file
View File

@@ -0,0 +1,9 @@
<template>
<UApp>
<NuxtPage/>
</UApp>
</template>
<style>
@import "assets/css/main.css";
</style>

2
web/assets/css/main.css Normal file
View File

@@ -0,0 +1,2 @@
@import "tailwindcss";
@import "@nuxt/ui";

View File

@@ -0,0 +1,3 @@
@tailwind base;
@tailwind components;
@tailwind utilities;

1999
web/bun.lock Normal file

File diff suppressed because it is too large Load Diff

6
web/nuxt.config.ts Normal file
View File

@@ -0,0 +1,6 @@
// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
compatibilityDate: '2025-05-15',
devtools: { enabled: true },
modules: ['@nuxt/icon', '@nuxt/ui', '@nuxtjs/tailwindcss']
})

17
web/pages/index.vue Normal file
View File

@@ -0,0 +1,17 @@
<template>
<main class="flex items-center justify-center min-w-screen min-h-screen">
<UButton icon="material-symbols:lock" size="xl" color="primary" variant="solid">Lock</UButton>
{{ res }}
</main>
</template>
<script lang="ts" setup>
const token = useCookie("token")
onMounted(() => {
if (!token.value) {
return navigateTo("/token")
}
console.log(token.value)
})
</script>

42
web/pages/token.vue Normal file
View File

@@ -0,0 +1,42 @@
<template>
<main class="flex items-center justify-center min-w-screen min-h-screen">
<UForm :schema="schema" :state="state" @submit="onSubmit" class="flex flex-col items-end justify-center gap-y-2">
<UFormField label="Token" name="token" size="xl" required>
<UInput v-model="state.token" placeholder="Your token..." size="xl"/>
</UFormField>
<UButton type="submit" size="xl">
Submit
</UButton>
</UForm>
</main>
</template>
<script lang="ts" setup>
import * as v from "valibot"
import type { FormSubmitEvent } from "@nuxt/ui"
const schema = v.object({
token: v.pipe(v.string(), v.nonEmpty("Please enter your token"))
})
type Schema = v.InferOutput<typeof schema>
const state = reactive({
token: ""
})
const toast = useToast()
async function onSubmit(event: FormSubmitEvent<Schema>) {
const token = event.data.token
const res = await $fetch("https://door.svitan.dev/open", {
method: "GET",
headers: {
Authorization: `Bearer ${token}`
}
})
console.log(token)
console.log(res)
toast.add({ title: "Token saved", color: "success" })
}
</script>

BIN
web/public/favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 264 KiB

2
web/public/robots.txt Normal file
View File

@@ -0,0 +1,2 @@
User-Agent: *
Disallow: /

3
web/server/tsconfig.json Normal file
View File

@@ -0,0 +1,3 @@
{
"extends": "../.nuxt/tsconfig.server.json"
}

11
web/tailwind.config.js Normal file
View File

@@ -0,0 +1,11 @@
module.exports = {
purge: [],
darkMode: "class", // or 'media' or 'class'
theme: {
extend: {},
},
variants: {
extend: {},
},
plugins: [],
}

4
web/tsconfig.json Normal file
View File

@@ -0,0 +1,4 @@
{
// https://nuxt.com/docs/guide/concepts/typescript
"extends": "./.nuxt/tsconfig.json"
}