From 23afdfc7b2df571d8cce305e1321f4155d5f5c62 Mon Sep 17 00:00:00 2001 From: yujonglee Date: Thu, 19 Dec 2024 13:17:31 +0900 Subject: [PATCH 01/13] mark existing as old --- {server => server-old}/.dockerignore | 0 {server => server-old}/.formatter.exs | 0 {server => server-old}/.gitignore | 0 {server => server-old}/.tool-versions | 0 {server => server-old}/Dockerfile | 0 {server => server-old}/README.md | 0 {server => server-old}/Taskfile.yaml | 0 {server => server-old}/config/config.exs | 0 {server => server-old}/config/dev.exs | 0 {server => server-old}/config/prod.exs | 0 {server => server-old}/config/runtime.exs | 0 {server => server-old}/config/test.exs | 0 {server => server-old}/debug.sh | 0 {server => server-old}/docker-compose.yaml | 0 {server => server-old}/fly.toml | 0 {server => server-old}/lib/hypr.ex | 0 {server => server-old}/lib/hypr/application.ex | 0 {server => server-old}/lib/hypr/release.ex | 0 {server => server-old}/lib/hypr/repo.ex | 0 .../lib/hypr/stripe_webhook_listener.ex | 0 {server => server-old}/lib/hypr/stt/deepgram.ex | 0 {server => server-old}/lib/hypr/stt/stt.ex | 0 {server => server-old}/lib/hypr_web.ex | 0 .../lib/hypr_web/controllers/error_json.ex | 0 {server => server-old}/lib/hypr_web/endpoint.ex | 0 {server => server-old}/lib/hypr_web/plugs/health.ex | 0 {server => server-old}/lib/hypr_web/router.ex | 0 {server => server-old}/lib/hypr_web/session.ex | 0 .../lib/hypr_web/stripe_webhook_handler.ex | 0 {server => server-old}/lib/hypr_web/telemetry.ex | 0 {server => server-old}/lib/proto/v0.pb.ex | 0 {server => server-old}/mix.exs | 0 {server => server-old}/mix.lock | 0 .../priv/repo/migrations/.formatter.exs | 0 {server => server-old}/priv/repo/seeds.exs | 0 {server => server-old}/priv/static/favicon.ico | Bin {server => server-old}/priv/static/robots.txt | 0 {server => server-old}/rel/env.sh.eex | 0 {server => server-old}/rel/overlays/bin/migrate | 0 {server => server-old}/rel/overlays/bin/migrate.bat | 0 {server => server-old}/rel/overlays/bin/server | 0 {server => server-old}/rel/overlays/bin/server.bat | 0 .../test/hypr_web/controllers/error_json_test.exs | 0 {server => server-old}/test/support/conn_case.ex | 0 {server => server-old}/test/support/data_case.ex | 0 {server => server-old}/test/test_helper.exs | 0 46 files changed, 0 insertions(+), 0 deletions(-) rename {server => server-old}/.dockerignore (100%) rename {server => server-old}/.formatter.exs (100%) rename {server => server-old}/.gitignore (100%) rename {server => server-old}/.tool-versions (100%) rename {server => server-old}/Dockerfile (100%) rename {server => server-old}/README.md (100%) rename {server => server-old}/Taskfile.yaml (100%) rename {server => server-old}/config/config.exs (100%) rename {server => server-old}/config/dev.exs (100%) rename {server => server-old}/config/prod.exs (100%) rename {server => server-old}/config/runtime.exs (100%) rename {server => server-old}/config/test.exs (100%) rename {server => server-old}/debug.sh (100%) rename {server => server-old}/docker-compose.yaml (100%) rename {server => server-old}/fly.toml (100%) rename {server => server-old}/lib/hypr.ex (100%) rename {server => server-old}/lib/hypr/application.ex (100%) rename {server => server-old}/lib/hypr/release.ex (100%) rename {server => server-old}/lib/hypr/repo.ex (100%) rename {server => server-old}/lib/hypr/stripe_webhook_listener.ex (100%) rename {server => server-old}/lib/hypr/stt/deepgram.ex (100%) rename {server => server-old}/lib/hypr/stt/stt.ex (100%) rename {server => server-old}/lib/hypr_web.ex (100%) rename {server => server-old}/lib/hypr_web/controllers/error_json.ex (100%) rename {server => server-old}/lib/hypr_web/endpoint.ex (100%) rename {server => server-old}/lib/hypr_web/plugs/health.ex (100%) rename {server => server-old}/lib/hypr_web/router.ex (100%) rename {server => server-old}/lib/hypr_web/session.ex (100%) rename {server => server-old}/lib/hypr_web/stripe_webhook_handler.ex (100%) rename {server => server-old}/lib/hypr_web/telemetry.ex (100%) rename {server => server-old}/lib/proto/v0.pb.ex (100%) rename {server => server-old}/mix.exs (100%) rename {server => server-old}/mix.lock (100%) rename {server => server-old}/priv/repo/migrations/.formatter.exs (100%) rename {server => server-old}/priv/repo/seeds.exs (100%) rename {server => server-old}/priv/static/favicon.ico (100%) rename {server => server-old}/priv/static/robots.txt (100%) rename {server => server-old}/rel/env.sh.eex (100%) rename {server => server-old}/rel/overlays/bin/migrate (100%) rename {server => server-old}/rel/overlays/bin/migrate.bat (100%) rename {server => server-old}/rel/overlays/bin/server (100%) rename {server => server-old}/rel/overlays/bin/server.bat (100%) rename {server => server-old}/test/hypr_web/controllers/error_json_test.exs (100%) rename {server => server-old}/test/support/conn_case.ex (100%) rename {server => server-old}/test/support/data_case.ex (100%) rename {server => server-old}/test/test_helper.exs (100%) diff --git a/server/.dockerignore b/server-old/.dockerignore similarity index 100% rename from server/.dockerignore rename to server-old/.dockerignore diff --git a/server/.formatter.exs b/server-old/.formatter.exs similarity index 100% rename from server/.formatter.exs rename to server-old/.formatter.exs diff --git a/server/.gitignore b/server-old/.gitignore similarity index 100% rename from server/.gitignore rename to server-old/.gitignore diff --git a/server/.tool-versions b/server-old/.tool-versions similarity index 100% rename from server/.tool-versions rename to server-old/.tool-versions diff --git a/server/Dockerfile b/server-old/Dockerfile similarity index 100% rename from server/Dockerfile rename to server-old/Dockerfile diff --git a/server/README.md b/server-old/README.md similarity index 100% rename from server/README.md rename to server-old/README.md diff --git a/server/Taskfile.yaml b/server-old/Taskfile.yaml similarity index 100% rename from server/Taskfile.yaml rename to server-old/Taskfile.yaml diff --git a/server/config/config.exs b/server-old/config/config.exs similarity index 100% rename from server/config/config.exs rename to server-old/config/config.exs diff --git a/server/config/dev.exs b/server-old/config/dev.exs similarity index 100% rename from server/config/dev.exs rename to server-old/config/dev.exs diff --git a/server/config/prod.exs b/server-old/config/prod.exs similarity index 100% rename from server/config/prod.exs rename to server-old/config/prod.exs diff --git a/server/config/runtime.exs b/server-old/config/runtime.exs similarity index 100% rename from server/config/runtime.exs rename to server-old/config/runtime.exs diff --git a/server/config/test.exs b/server-old/config/test.exs similarity index 100% rename from server/config/test.exs rename to server-old/config/test.exs diff --git a/server/debug.sh b/server-old/debug.sh similarity index 100% rename from server/debug.sh rename to server-old/debug.sh diff --git a/server/docker-compose.yaml b/server-old/docker-compose.yaml similarity index 100% rename from server/docker-compose.yaml rename to server-old/docker-compose.yaml diff --git a/server/fly.toml b/server-old/fly.toml similarity index 100% rename from server/fly.toml rename to server-old/fly.toml diff --git a/server/lib/hypr.ex b/server-old/lib/hypr.ex similarity index 100% rename from server/lib/hypr.ex rename to server-old/lib/hypr.ex diff --git a/server/lib/hypr/application.ex b/server-old/lib/hypr/application.ex similarity index 100% rename from server/lib/hypr/application.ex rename to server-old/lib/hypr/application.ex diff --git a/server/lib/hypr/release.ex b/server-old/lib/hypr/release.ex similarity index 100% rename from server/lib/hypr/release.ex rename to server-old/lib/hypr/release.ex diff --git a/server/lib/hypr/repo.ex b/server-old/lib/hypr/repo.ex similarity index 100% rename from server/lib/hypr/repo.ex rename to server-old/lib/hypr/repo.ex diff --git a/server/lib/hypr/stripe_webhook_listener.ex b/server-old/lib/hypr/stripe_webhook_listener.ex similarity index 100% rename from server/lib/hypr/stripe_webhook_listener.ex rename to server-old/lib/hypr/stripe_webhook_listener.ex diff --git a/server/lib/hypr/stt/deepgram.ex b/server-old/lib/hypr/stt/deepgram.ex similarity index 100% rename from server/lib/hypr/stt/deepgram.ex rename to server-old/lib/hypr/stt/deepgram.ex diff --git a/server/lib/hypr/stt/stt.ex b/server-old/lib/hypr/stt/stt.ex similarity index 100% rename from server/lib/hypr/stt/stt.ex rename to server-old/lib/hypr/stt/stt.ex diff --git a/server/lib/hypr_web.ex b/server-old/lib/hypr_web.ex similarity index 100% rename from server/lib/hypr_web.ex rename to server-old/lib/hypr_web.ex diff --git a/server/lib/hypr_web/controllers/error_json.ex b/server-old/lib/hypr_web/controllers/error_json.ex similarity index 100% rename from server/lib/hypr_web/controllers/error_json.ex rename to server-old/lib/hypr_web/controllers/error_json.ex diff --git a/server/lib/hypr_web/endpoint.ex b/server-old/lib/hypr_web/endpoint.ex similarity index 100% rename from server/lib/hypr_web/endpoint.ex rename to server-old/lib/hypr_web/endpoint.ex diff --git a/server/lib/hypr_web/plugs/health.ex b/server-old/lib/hypr_web/plugs/health.ex similarity index 100% rename from server/lib/hypr_web/plugs/health.ex rename to server-old/lib/hypr_web/plugs/health.ex diff --git a/server/lib/hypr_web/router.ex b/server-old/lib/hypr_web/router.ex similarity index 100% rename from server/lib/hypr_web/router.ex rename to server-old/lib/hypr_web/router.ex diff --git a/server/lib/hypr_web/session.ex b/server-old/lib/hypr_web/session.ex similarity index 100% rename from server/lib/hypr_web/session.ex rename to server-old/lib/hypr_web/session.ex diff --git a/server/lib/hypr_web/stripe_webhook_handler.ex b/server-old/lib/hypr_web/stripe_webhook_handler.ex similarity index 100% rename from server/lib/hypr_web/stripe_webhook_handler.ex rename to server-old/lib/hypr_web/stripe_webhook_handler.ex diff --git a/server/lib/hypr_web/telemetry.ex b/server-old/lib/hypr_web/telemetry.ex similarity index 100% rename from server/lib/hypr_web/telemetry.ex rename to server-old/lib/hypr_web/telemetry.ex diff --git a/server/lib/proto/v0.pb.ex b/server-old/lib/proto/v0.pb.ex similarity index 100% rename from server/lib/proto/v0.pb.ex rename to server-old/lib/proto/v0.pb.ex diff --git a/server/mix.exs b/server-old/mix.exs similarity index 100% rename from server/mix.exs rename to server-old/mix.exs diff --git a/server/mix.lock b/server-old/mix.lock similarity index 100% rename from server/mix.lock rename to server-old/mix.lock diff --git a/server/priv/repo/migrations/.formatter.exs b/server-old/priv/repo/migrations/.formatter.exs similarity index 100% rename from server/priv/repo/migrations/.formatter.exs rename to server-old/priv/repo/migrations/.formatter.exs diff --git a/server/priv/repo/seeds.exs b/server-old/priv/repo/seeds.exs similarity index 100% rename from server/priv/repo/seeds.exs rename to server-old/priv/repo/seeds.exs diff --git a/server/priv/static/favicon.ico b/server-old/priv/static/favicon.ico similarity index 100% rename from server/priv/static/favicon.ico rename to server-old/priv/static/favicon.ico diff --git a/server/priv/static/robots.txt b/server-old/priv/static/robots.txt similarity index 100% rename from server/priv/static/robots.txt rename to server-old/priv/static/robots.txt diff --git a/server/rel/env.sh.eex b/server-old/rel/env.sh.eex similarity index 100% rename from server/rel/env.sh.eex rename to server-old/rel/env.sh.eex diff --git a/server/rel/overlays/bin/migrate b/server-old/rel/overlays/bin/migrate similarity index 100% rename from server/rel/overlays/bin/migrate rename to server-old/rel/overlays/bin/migrate diff --git a/server/rel/overlays/bin/migrate.bat b/server-old/rel/overlays/bin/migrate.bat similarity index 100% rename from server/rel/overlays/bin/migrate.bat rename to server-old/rel/overlays/bin/migrate.bat diff --git a/server/rel/overlays/bin/server b/server-old/rel/overlays/bin/server similarity index 100% rename from server/rel/overlays/bin/server rename to server-old/rel/overlays/bin/server diff --git a/server/rel/overlays/bin/server.bat b/server-old/rel/overlays/bin/server.bat similarity index 100% rename from server/rel/overlays/bin/server.bat rename to server-old/rel/overlays/bin/server.bat diff --git a/server/test/hypr_web/controllers/error_json_test.exs b/server-old/test/hypr_web/controllers/error_json_test.exs similarity index 100% rename from server/test/hypr_web/controllers/error_json_test.exs rename to server-old/test/hypr_web/controllers/error_json_test.exs diff --git a/server/test/support/conn_case.ex b/server-old/test/support/conn_case.ex similarity index 100% rename from server/test/support/conn_case.ex rename to server-old/test/support/conn_case.ex diff --git a/server/test/support/data_case.ex b/server-old/test/support/data_case.ex similarity index 100% rename from server/test/support/data_case.ex rename to server-old/test/support/data_case.ex diff --git a/server/test/test_helper.exs b/server-old/test/test_helper.exs similarity index 100% rename from server/test/test_helper.exs rename to server-old/test/test_helper.exs From dd2835b6ca559f24e9d7ba691e2657d9992160ca Mon Sep 17 00:00:00 2001 From: yujonglee Date: Thu, 19 Dec 2024 13:18:20 +0900 Subject: [PATCH 02/13] init new one --- server/.formatter.exs | 6 + server/.gitignore | 37 + server/README.md | 18 + server/assets/css/app.css | 5 + server/assets/js/app.js | 44 ++ server/assets/tailwind.config.js | 74 ++ server/assets/vendor/topbar.js | 165 +++++ server/config/config.exs | 66 ++ server/config/dev.exs | 85 +++ server/config/prod.exs | 20 + server/config/runtime.exs | 117 +++ server/config/test.exs | 37 + server/lib/hypr.ex | 9 + server/lib/hypr/application.ex | 36 + server/lib/hypr/mailer.ex | 3 + server/lib/hypr/repo.ex | 5 + server/lib/hypr_web.ex | 113 +++ .../hypr_web/components/core_components.ex | 676 ++++++++++++++++++ server/lib/hypr_web/components/layouts.ex | 14 + .../hypr_web/components/layouts/app.html.heex | 32 + .../components/layouts/root.html.heex | 17 + server/lib/hypr_web/controllers/error_html.ex | 24 + server/lib/hypr_web/controllers/error_json.ex | 21 + .../hypr_web/controllers/page_controller.ex | 9 + server/lib/hypr_web/controllers/page_html.ex | 10 + .../controllers/page_html/home.html.heex | 222 ++++++ server/lib/hypr_web/endpoint.ex | 49 ++ server/lib/hypr_web/gettext.ex | 24 + server/lib/hypr_web/router.ex | 37 + server/lib/hypr_web/telemetry.ex | 92 +++ server/mix.exs | 85 +++ server/mix.lock | 40 ++ server/priv/gettext/en/LC_MESSAGES/errors.po | 112 +++ server/priv/gettext/errors.pot | 109 +++ server/priv/repo/migrations/.formatter.exs | 4 + server/priv/repo/seeds.exs | 11 + server/priv/static/favicon.ico | Bin 0 -> 152 bytes server/priv/static/images/logo.svg | 6 + server/priv/static/robots.txt | 5 + .../hypr_web/controllers/error_html_test.exs | 14 + .../hypr_web/controllers/error_json_test.exs | 12 + .../controllers/page_controller_test.exs | 8 + server/test/support/conn_case.ex | 38 + server/test/support/data_case.ex | 58 ++ server/test/test_helper.exs | 2 + 45 files changed, 2571 insertions(+) create mode 100644 server/.formatter.exs create mode 100644 server/.gitignore create mode 100644 server/README.md create mode 100644 server/assets/css/app.css create mode 100644 server/assets/js/app.js create mode 100644 server/assets/tailwind.config.js create mode 100644 server/assets/vendor/topbar.js create mode 100644 server/config/config.exs create mode 100644 server/config/dev.exs create mode 100644 server/config/prod.exs create mode 100644 server/config/runtime.exs create mode 100644 server/config/test.exs create mode 100644 server/lib/hypr.ex create mode 100644 server/lib/hypr/application.ex create mode 100644 server/lib/hypr/mailer.ex create mode 100644 server/lib/hypr/repo.ex create mode 100644 server/lib/hypr_web.ex create mode 100644 server/lib/hypr_web/components/core_components.ex create mode 100644 server/lib/hypr_web/components/layouts.ex create mode 100644 server/lib/hypr_web/components/layouts/app.html.heex create mode 100644 server/lib/hypr_web/components/layouts/root.html.heex create mode 100644 server/lib/hypr_web/controllers/error_html.ex create mode 100644 server/lib/hypr_web/controllers/error_json.ex create mode 100644 server/lib/hypr_web/controllers/page_controller.ex create mode 100644 server/lib/hypr_web/controllers/page_html.ex create mode 100644 server/lib/hypr_web/controllers/page_html/home.html.heex create mode 100644 server/lib/hypr_web/endpoint.ex create mode 100644 server/lib/hypr_web/gettext.ex create mode 100644 server/lib/hypr_web/router.ex create mode 100644 server/lib/hypr_web/telemetry.ex create mode 100644 server/mix.exs create mode 100644 server/mix.lock create mode 100644 server/priv/gettext/en/LC_MESSAGES/errors.po create mode 100644 server/priv/gettext/errors.pot create mode 100644 server/priv/repo/migrations/.formatter.exs create mode 100644 server/priv/repo/seeds.exs create mode 100644 server/priv/static/favicon.ico create mode 100644 server/priv/static/images/logo.svg create mode 100644 server/priv/static/robots.txt create mode 100644 server/test/hypr_web/controllers/error_html_test.exs create mode 100644 server/test/hypr_web/controllers/error_json_test.exs create mode 100644 server/test/hypr_web/controllers/page_controller_test.exs create mode 100644 server/test/support/conn_case.ex create mode 100644 server/test/support/data_case.ex create mode 100644 server/test/test_helper.exs diff --git a/server/.formatter.exs b/server/.formatter.exs new file mode 100644 index 0000000000..ef8840ce6f --- /dev/null +++ b/server/.formatter.exs @@ -0,0 +1,6 @@ +[ + import_deps: [:ecto, :ecto_sql, :phoenix], + subdirectories: ["priv/*/migrations"], + plugins: [Phoenix.LiveView.HTMLFormatter], + inputs: ["*.{heex,ex,exs}", "{config,lib,test}/**/*.{heex,ex,exs}", "priv/*/seeds.exs"] +] diff --git a/server/.gitignore b/server/.gitignore new file mode 100644 index 0000000000..765fb92303 --- /dev/null +++ b/server/.gitignore @@ -0,0 +1,37 @@ +# The directory Mix will write compiled artifacts to. +/_build/ + +# If you run "mix test --cover", coverage assets end up here. +/cover/ + +# The directory Mix downloads your dependencies sources to. +/deps/ + +# Where 3rd-party dependencies like ExDoc output generated docs. +/doc/ + +# Ignore .fetch files in case you like to edit your project deps locally. +/.fetch + +# If the VM crashes, it generates a dump, let's ignore it too. +erl_crash.dump + +# Also ignore archive artifacts (built via "mix archive.build"). +*.ez + +# Temporary files, for example, from tests. +/tmp/ + +# Ignore package tarball (built via "mix hex.build"). +hypr-*.tar + +# Ignore assets that are produced by build tools. +/priv/static/assets/ + +# Ignore digested assets cache. +/priv/static/cache_manifest.json + +# In case you use Node.js/npm, you want to ignore these. +npm-debug.log +/assets/node_modules/ + diff --git a/server/README.md b/server/README.md new file mode 100644 index 0000000000..8f2515c3e8 --- /dev/null +++ b/server/README.md @@ -0,0 +1,18 @@ +# Hypr + +To start your Phoenix server: + + * Run `mix setup` to install and setup dependencies + * Start Phoenix endpoint with `mix phx.server` or inside IEx with `iex -S mix phx.server` + +Now you can visit [`localhost:4000`](http://localhost:4000) from your browser. + +Ready to run in production? Please [check our deployment guides](https://hexdocs.pm/phoenix/deployment.html). + +## Learn more + + * Official website: https://www.phoenixframework.org/ + * Guides: https://hexdocs.pm/phoenix/overview.html + * Docs: https://hexdocs.pm/phoenix + * Forum: https://elixirforum.com/c/phoenix-forum + * Source: https://github.com/phoenixframework/phoenix diff --git a/server/assets/css/app.css b/server/assets/css/app.css new file mode 100644 index 0000000000..378c8f9056 --- /dev/null +++ b/server/assets/css/app.css @@ -0,0 +1,5 @@ +@import "tailwindcss/base"; +@import "tailwindcss/components"; +@import "tailwindcss/utilities"; + +/* This file is for your main application CSS */ diff --git a/server/assets/js/app.js b/server/assets/js/app.js new file mode 100644 index 0000000000..d5e278afe5 --- /dev/null +++ b/server/assets/js/app.js @@ -0,0 +1,44 @@ +// If you want to use Phoenix channels, run `mix help phx.gen.channel` +// to get started and then uncomment the line below. +// import "./user_socket.js" + +// You can include dependencies in two ways. +// +// The simplest option is to put them in assets/vendor and +// import them using relative paths: +// +// import "../vendor/some-package.js" +// +// Alternatively, you can `npm install some-package --prefix assets` and import +// them using a path starting with the package name: +// +// import "some-package" +// + +// Include phoenix_html to handle method=PUT/DELETE in forms and buttons. +import "phoenix_html" +// Establish Phoenix Socket and LiveView configuration. +import {Socket} from "phoenix" +import {LiveSocket} from "phoenix_live_view" +import topbar from "../vendor/topbar" + +let csrfToken = document.querySelector("meta[name='csrf-token']").getAttribute("content") +let liveSocket = new LiveSocket("/live", Socket, { + longPollFallbackMs: 2500, + params: {_csrf_token: csrfToken} +}) + +// Show progress bar on live navigation and form submits +topbar.config({barColors: {0: "#29d"}, shadowColor: "rgba(0, 0, 0, .3)"}) +window.addEventListener("phx:page-loading-start", _info => topbar.show(300)) +window.addEventListener("phx:page-loading-stop", _info => topbar.hide()) + +// connect if there are any LiveViews on the page +liveSocket.connect() + +// expose liveSocket on window for web console debug logs and latency simulation: +// >> liveSocket.enableDebug() +// >> liveSocket.enableLatencySim(1000) // enabled for duration of browser session +// >> liveSocket.disableLatencySim() +window.liveSocket = liveSocket + diff --git a/server/assets/tailwind.config.js b/server/assets/tailwind.config.js new file mode 100644 index 0000000000..5365a303b8 --- /dev/null +++ b/server/assets/tailwind.config.js @@ -0,0 +1,74 @@ +// See the Tailwind configuration guide for advanced usage +// https://tailwindcss.com/docs/configuration + +const plugin = require("tailwindcss/plugin") +const fs = require("fs") +const path = require("path") + +module.exports = { + content: [ + "./js/**/*.js", + "../lib/hypr_web.ex", + "../lib/hypr_web/**/*.*ex" + ], + theme: { + extend: { + colors: { + brand: "#FD4F00", + } + }, + }, + plugins: [ + require("@tailwindcss/forms"), + // Allows prefixing tailwind classes with LiveView classes to add rules + // only when LiveView classes are applied, for example: + // + //
+ // + plugin(({addVariant}) => addVariant("phx-click-loading", [".phx-click-loading&", ".phx-click-loading &"])), + plugin(({addVariant}) => addVariant("phx-submit-loading", [".phx-submit-loading&", ".phx-submit-loading &"])), + plugin(({addVariant}) => addVariant("phx-change-loading", [".phx-change-loading&", ".phx-change-loading &"])), + + // Embeds Heroicons (https://heroicons.com) into your app.css bundle + // See your `CoreComponents.icon/1` for more information. + // + plugin(function({matchComponents, theme}) { + let iconsDir = path.join(__dirname, "../deps/heroicons/optimized") + let values = {} + let icons = [ + ["", "/24/outline"], + ["-solid", "/24/solid"], + ["-mini", "/20/solid"], + ["-micro", "/16/solid"] + ] + icons.forEach(([suffix, dir]) => { + fs.readdirSync(path.join(iconsDir, dir)).forEach(file => { + let name = path.basename(file, ".svg") + suffix + values[name] = {name, fullPath: path.join(iconsDir, dir, file)} + }) + }) + matchComponents({ + "hero": ({name, fullPath}) => { + let content = fs.readFileSync(fullPath).toString().replace(/\r?\n|\r/g, "") + let size = theme("spacing.6") + if (name.endsWith("-mini")) { + size = theme("spacing.5") + } else if (name.endsWith("-micro")) { + size = theme("spacing.4") + } + return { + [`--hero-${name}`]: `url('data:image/svg+xml;utf8,${content}')`, + "-webkit-mask": `var(--hero-${name})`, + "mask": `var(--hero-${name})`, + "mask-repeat": "no-repeat", + "background-color": "currentColor", + "vertical-align": "middle", + "display": "inline-block", + "width": size, + "height": size + } + } + }, {values}) + }) + ] +} diff --git a/server/assets/vendor/topbar.js b/server/assets/vendor/topbar.js new file mode 100644 index 0000000000..41957274d7 --- /dev/null +++ b/server/assets/vendor/topbar.js @@ -0,0 +1,165 @@ +/** + * @license MIT + * topbar 2.0.0, 2023-02-04 + * https://buunguyen.github.io/topbar + * Copyright (c) 2021 Buu Nguyen + */ +(function (window, document) { + "use strict"; + + // https://gist.github.com/paulirish/1579671 + (function () { + var lastTime = 0; + var vendors = ["ms", "moz", "webkit", "o"]; + for (var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) { + window.requestAnimationFrame = + window[vendors[x] + "RequestAnimationFrame"]; + window.cancelAnimationFrame = + window[vendors[x] + "CancelAnimationFrame"] || + window[vendors[x] + "CancelRequestAnimationFrame"]; + } + if (!window.requestAnimationFrame) + window.requestAnimationFrame = function (callback, element) { + var currTime = new Date().getTime(); + var timeToCall = Math.max(0, 16 - (currTime - lastTime)); + var id = window.setTimeout(function () { + callback(currTime + timeToCall); + }, timeToCall); + lastTime = currTime + timeToCall; + return id; + }; + if (!window.cancelAnimationFrame) + window.cancelAnimationFrame = function (id) { + clearTimeout(id); + }; + })(); + + var canvas, + currentProgress, + showing, + progressTimerId = null, + fadeTimerId = null, + delayTimerId = null, + addEvent = function (elem, type, handler) { + if (elem.addEventListener) elem.addEventListener(type, handler, false); + else if (elem.attachEvent) elem.attachEvent("on" + type, handler); + else elem["on" + type] = handler; + }, + options = { + autoRun: true, + barThickness: 3, + barColors: { + 0: "rgba(26, 188, 156, .9)", + ".25": "rgba(52, 152, 219, .9)", + ".50": "rgba(241, 196, 15, .9)", + ".75": "rgba(230, 126, 34, .9)", + "1.0": "rgba(211, 84, 0, .9)", + }, + shadowBlur: 10, + shadowColor: "rgba(0, 0, 0, .6)", + className: null, + }, + repaint = function () { + canvas.width = window.innerWidth; + canvas.height = options.barThickness * 5; // need space for shadow + + var ctx = canvas.getContext("2d"); + ctx.shadowBlur = options.shadowBlur; + ctx.shadowColor = options.shadowColor; + + var lineGradient = ctx.createLinearGradient(0, 0, canvas.width, 0); + for (var stop in options.barColors) + lineGradient.addColorStop(stop, options.barColors[stop]); + ctx.lineWidth = options.barThickness; + ctx.beginPath(); + ctx.moveTo(0, options.barThickness / 2); + ctx.lineTo( + Math.ceil(currentProgress * canvas.width), + options.barThickness / 2 + ); + ctx.strokeStyle = lineGradient; + ctx.stroke(); + }, + createCanvas = function () { + canvas = document.createElement("canvas"); + var style = canvas.style; + style.position = "fixed"; + style.top = style.left = style.right = style.margin = style.padding = 0; + style.zIndex = 100001; + style.display = "none"; + if (options.className) canvas.classList.add(options.className); + document.body.appendChild(canvas); + addEvent(window, "resize", repaint); + }, + topbar = { + config: function (opts) { + for (var key in opts) + if (options.hasOwnProperty(key)) options[key] = opts[key]; + }, + show: function (delay) { + if (showing) return; + if (delay) { + if (delayTimerId) return; + delayTimerId = setTimeout(() => topbar.show(), delay); + } else { + showing = true; + if (fadeTimerId !== null) window.cancelAnimationFrame(fadeTimerId); + if (!canvas) createCanvas(); + canvas.style.opacity = 1; + canvas.style.display = "block"; + topbar.progress(0); + if (options.autoRun) { + (function loop() { + progressTimerId = window.requestAnimationFrame(loop); + topbar.progress( + "+" + 0.05 * Math.pow(1 - Math.sqrt(currentProgress), 2) + ); + })(); + } + } + }, + progress: function (to) { + if (typeof to === "undefined") return currentProgress; + if (typeof to === "string") { + to = + (to.indexOf("+") >= 0 || to.indexOf("-") >= 0 + ? currentProgress + : 0) + parseFloat(to); + } + currentProgress = to > 1 ? 1 : to; + repaint(); + return currentProgress; + }, + hide: function () { + clearTimeout(delayTimerId); + delayTimerId = null; + if (!showing) return; + showing = false; + if (progressTimerId != null) { + window.cancelAnimationFrame(progressTimerId); + progressTimerId = null; + } + (function loop() { + if (topbar.progress("+.1") >= 1) { + canvas.style.opacity -= 0.05; + if (canvas.style.opacity <= 0.05) { + canvas.style.display = "none"; + fadeTimerId = null; + return; + } + } + fadeTimerId = window.requestAnimationFrame(loop); + })(); + }, + }; + + if (typeof module === "object" && typeof module.exports === "object") { + module.exports = topbar; + } else if (typeof define === "function" && define.amd) { + define(function () { + return topbar; + }); + } else { + this.topbar = topbar; + } +}.call(this, window, document)); diff --git a/server/config/config.exs b/server/config/config.exs new file mode 100644 index 0000000000..8f3410250e --- /dev/null +++ b/server/config/config.exs @@ -0,0 +1,66 @@ +# This file is responsible for configuring your application +# and its dependencies with the aid of the Config module. +# +# This configuration file is loaded before any dependency and +# is restricted to this project. + +# General application configuration +import Config + +config :hypr, + ecto_repos: [Hypr.Repo], + generators: [timestamp_type: :utc_datetime] + +# Configures the endpoint +config :hypr, HyprWeb.Endpoint, + url: [host: "localhost"], + adapter: Bandit.PhoenixAdapter, + render_errors: [ + formats: [html: HyprWeb.ErrorHTML, json: HyprWeb.ErrorJSON], + layout: false + ], + pubsub_server: Hypr.PubSub, + live_view: [signing_salt: "hhkuEfA8"] + +# Configures the mailer +# +# By default it uses the "Local" adapter which stores the emails +# locally. You can see the emails in your browser, at "/dev/mailbox". +# +# For production it's recommended to configure a different adapter +# at the `config/runtime.exs`. +config :hypr, Hypr.Mailer, adapter: Swoosh.Adapters.Local + +# Configure esbuild (the version is required) +config :esbuild, + version: "0.17.11", + hypr: [ + args: + ~w(js/app.js --bundle --target=es2017 --outdir=../priv/static/assets --external:/fonts/* --external:/images/*), + cd: Path.expand("../assets", __DIR__), + env: %{"NODE_PATH" => Path.expand("../deps", __DIR__)} + ] + +# Configure tailwind (the version is required) +config :tailwind, + version: "3.4.3", + hypr: [ + args: ~w( + --config=tailwind.config.js + --input=css/app.css + --output=../priv/static/assets/app.css + ), + cd: Path.expand("../assets", __DIR__) + ] + +# Configures Elixir's Logger +config :logger, :console, + format: "$time $metadata[$level] $message\n", + metadata: [:request_id] + +# Use Jason for JSON parsing in Phoenix +config :phoenix, :json_library, Jason + +# Import environment specific config. This must remain at the bottom +# of this file so it overrides the configuration defined above. +import_config "#{config_env()}.exs" diff --git a/server/config/dev.exs b/server/config/dev.exs new file mode 100644 index 0000000000..8b4e13c407 --- /dev/null +++ b/server/config/dev.exs @@ -0,0 +1,85 @@ +import Config + +# Configure your database +config :hypr, Hypr.Repo, + username: "postgres", + password: "postgres", + hostname: "localhost", + database: "hypr_dev", + stacktrace: true, + show_sensitive_data_on_connection_error: true, + pool_size: 10 + +# For development, we disable any cache and enable +# debugging and code reloading. +# +# The watchers configuration can be used to run external +# watchers to your application. For example, we can use it +# to bundle .js and .css sources. +config :hypr, HyprWeb.Endpoint, + # Binding to loopback ipv4 address prevents access from other machines. + # Change to `ip: {0, 0, 0, 0}` to allow access from other machines. + http: [ip: {127, 0, 0, 1}, port: 4000], + check_origin: false, + code_reloader: true, + debug_errors: true, + secret_key_base: "tCazuLUp2tzcSYGQ/bl9TK9UOYr8VdHhZJYzw2KDHj7U6dAGn+6ZvbLLYKZsKRKA", + watchers: [ + esbuild: {Esbuild, :install_and_run, [:hypr, ~w(--sourcemap=inline --watch)]}, + tailwind: {Tailwind, :install_and_run, [:hypr, ~w(--watch)]} + ] + +# ## SSL Support +# +# In order to use HTTPS in development, a self-signed +# certificate can be generated by running the following +# Mix task: +# +# mix phx.gen.cert +# +# Run `mix help phx.gen.cert` for more information. +# +# The `http:` config above can be replaced with: +# +# https: [ +# port: 4001, +# cipher_suite: :strong, +# keyfile: "priv/cert/selfsigned_key.pem", +# certfile: "priv/cert/selfsigned.pem" +# ], +# +# If desired, both `http:` and `https:` keys can be +# configured to run both http and https servers on +# different ports. + +# Watch static and templates for browser reloading. +config :hypr, HyprWeb.Endpoint, + live_reload: [ + patterns: [ + ~r"priv/static/(?!uploads/).*(js|css|png|jpeg|jpg|gif|svg)$", + ~r"priv/gettext/.*(po)$", + ~r"lib/hypr_web/(controllers|live|components)/.*(ex|heex)$" + ] + ] + +# Enable dev routes for dashboard and mailbox +config :hypr, dev_routes: true + +# Do not include metadata nor timestamps in development logs +config :logger, :console, format: "[$level] $message\n" + +# Set a higher stacktrace during development. Avoid configuring such +# in production as building large stacktraces may be expensive. +config :phoenix, :stacktrace_depth, 20 + +# Initialize plugs at runtime for faster development compilation +config :phoenix, :plug_init_mode, :runtime + +config :phoenix_live_view, + # Include HEEx debug annotations as HTML comments in rendered markup + debug_heex_annotations: true, + # Enable helpful, but potentially expensive runtime checks + enable_expensive_runtime_checks: true + +# Disable swoosh api client as it is only required for production adapters. +config :swoosh, :api_client, false diff --git a/server/config/prod.exs b/server/config/prod.exs new file mode 100644 index 0000000000..3376fe9b7c --- /dev/null +++ b/server/config/prod.exs @@ -0,0 +1,20 @@ +import Config + +# Note we also include the path to a cache manifest +# containing the digested version of static files. This +# manifest is generated by the `mix assets.deploy` task, +# which you should run after static files are built and +# before starting your production server. +config :hypr, HyprWeb.Endpoint, cache_static_manifest: "priv/static/cache_manifest.json" + +# Configures Swoosh API Client +config :swoosh, api_client: Swoosh.ApiClient.Finch, finch_name: Hypr.Finch + +# Disable Swoosh Local Memory Storage +config :swoosh, local: false + +# Do not print debug messages in production +config :logger, level: :info + +# Runtime production configuration, including reading +# of environment variables, is done on config/runtime.exs. diff --git a/server/config/runtime.exs b/server/config/runtime.exs new file mode 100644 index 0000000000..80e911fd28 --- /dev/null +++ b/server/config/runtime.exs @@ -0,0 +1,117 @@ +import Config + +# config/runtime.exs is executed for all environments, including +# during releases. It is executed after compilation and before the +# system starts, so it is typically used to load production configuration +# and secrets from environment variables or elsewhere. Do not define +# any compile-time configuration in here, as it won't be applied. +# The block below contains prod specific runtime configuration. + +# ## Using releases +# +# If you use `mix release`, you need to explicitly enable the server +# by passing the PHX_SERVER=true when you start it: +# +# PHX_SERVER=true bin/hypr start +# +# Alternatively, you can use `mix phx.gen.release` to generate a `bin/server` +# script that automatically sets the env var above. +if System.get_env("PHX_SERVER") do + config :hypr, HyprWeb.Endpoint, server: true +end + +if config_env() == :prod do + database_url = + System.get_env("DATABASE_URL") || + raise """ + environment variable DATABASE_URL is missing. + For example: ecto://USER:PASS@HOST/DATABASE + """ + + maybe_ipv6 = if System.get_env("ECTO_IPV6") in ~w(true 1), do: [:inet6], else: [] + + config :hypr, Hypr.Repo, + # ssl: true, + url: database_url, + pool_size: String.to_integer(System.get_env("POOL_SIZE") || "10"), + socket_options: maybe_ipv6 + + # The secret key base is used to sign/encrypt cookies and other secrets. + # A default value is used in config/dev.exs and config/test.exs but you + # want to use a different value for prod and you most likely don't want + # to check this value into version control, so we use an environment + # variable instead. + secret_key_base = + System.get_env("SECRET_KEY_BASE") || + raise """ + environment variable SECRET_KEY_BASE is missing. + You can generate one by calling: mix phx.gen.secret + """ + + host = System.get_env("PHX_HOST") || "example.com" + port = String.to_integer(System.get_env("PORT") || "4000") + + config :hypr, :dns_cluster_query, System.get_env("DNS_CLUSTER_QUERY") + + config :hypr, HyprWeb.Endpoint, + url: [host: host, port: 443, scheme: "https"], + http: [ + # Enable IPv6 and bind on all interfaces. + # Set it to {0, 0, 0, 0, 0, 0, 0, 1} for local network only access. + # See the documentation on https://hexdocs.pm/bandit/Bandit.html#t:options/0 + # for details about using IPv6 vs IPv4 and loopback vs public addresses. + ip: {0, 0, 0, 0, 0, 0, 0, 0}, + port: port + ], + secret_key_base: secret_key_base + + # ## SSL Support + # + # To get SSL working, you will need to add the `https` key + # to your endpoint configuration: + # + # config :hypr, HyprWeb.Endpoint, + # https: [ + # ..., + # port: 443, + # cipher_suite: :strong, + # keyfile: System.get_env("SOME_APP_SSL_KEY_PATH"), + # certfile: System.get_env("SOME_APP_SSL_CERT_PATH") + # ] + # + # The `cipher_suite` is set to `:strong` to support only the + # latest and more secure SSL ciphers. This means old browsers + # and clients may not be supported. You can set it to + # `:compatible` for wider support. + # + # `:keyfile` and `:certfile` expect an absolute path to the key + # and cert in disk or a relative path inside priv, for example + # "priv/ssl/server.key". For all supported SSL configuration + # options, see https://hexdocs.pm/plug/Plug.SSL.html#configure/1 + # + # We also recommend setting `force_ssl` in your config/prod.exs, + # ensuring no data is ever sent via http, always redirecting to https: + # + # config :hypr, HyprWeb.Endpoint, + # force_ssl: [hsts: true] + # + # Check `Plug.SSL` for all available options in `force_ssl`. + + # ## Configuring the mailer + # + # In production you need to configure the mailer to use a different adapter. + # Also, you may need to configure the Swoosh API client of your choice if you + # are not using SMTP. Here is an example of the configuration: + # + # config :hypr, Hypr.Mailer, + # adapter: Swoosh.Adapters.Mailgun, + # api_key: System.get_env("MAILGUN_API_KEY"), + # domain: System.get_env("MAILGUN_DOMAIN") + # + # For this example you need include a HTTP client required by Swoosh API client. + # Swoosh supports Hackney and Finch out of the box: + # + # config :swoosh, :api_client, Swoosh.ApiClient.Hackney + # + # See https://hexdocs.pm/swoosh/Swoosh.html#module-installation for details. +end diff --git a/server/config/test.exs b/server/config/test.exs new file mode 100644 index 0000000000..68cebe36d3 --- /dev/null +++ b/server/config/test.exs @@ -0,0 +1,37 @@ +import Config + +# Configure your database +# +# The MIX_TEST_PARTITION environment variable can be used +# to provide built-in test partitioning in CI environment. +# Run `mix help test` for more information. +config :hypr, Hypr.Repo, + username: "postgres", + password: "postgres", + hostname: "localhost", + database: "hypr_test#{System.get_env("MIX_TEST_PARTITION")}", + pool: Ecto.Adapters.SQL.Sandbox, + pool_size: System.schedulers_online() * 2 + +# We don't run a server during test. If one is required, +# you can enable the server option below. +config :hypr, HyprWeb.Endpoint, + http: [ip: {127, 0, 0, 1}, port: 4002], + secret_key_base: "LtJItTgjUPpx9eCrxP7JFNBRSztQSvcxKGDi92cshWq3R0twWqNFCjkvyjr/q2Xi", + server: false + +# In test we don't send emails +config :hypr, Hypr.Mailer, adapter: Swoosh.Adapters.Test + +# Disable swoosh api client as it is only required for production adapters +config :swoosh, :api_client, false + +# Print only warnings and errors during test +config :logger, level: :warning + +# Initialize plugs at runtime for faster test compilation +config :phoenix, :plug_init_mode, :runtime + +# Enable helpful, but potentially expensive runtime checks +config :phoenix_live_view, + enable_expensive_runtime_checks: true diff --git a/server/lib/hypr.ex b/server/lib/hypr.ex new file mode 100644 index 0000000000..ef4a5c2ed4 --- /dev/null +++ b/server/lib/hypr.ex @@ -0,0 +1,9 @@ +defmodule Hypr do + @moduledoc """ + Hypr keeps the contexts that define your domain + and business logic. + + Contexts are also responsible for managing your data, regardless + if it comes from the database, an external API or others. + """ +end diff --git a/server/lib/hypr/application.ex b/server/lib/hypr/application.ex new file mode 100644 index 0000000000..4f5401cac0 --- /dev/null +++ b/server/lib/hypr/application.ex @@ -0,0 +1,36 @@ +defmodule Hypr.Application do + # See https://hexdocs.pm/elixir/Application.html + # for more information on OTP Applications + @moduledoc false + + use Application + + @impl true + def start(_type, _args) do + children = [ + HyprWeb.Telemetry, + Hypr.Repo, + {DNSCluster, query: Application.get_env(:hypr, :dns_cluster_query) || :ignore}, + {Phoenix.PubSub, name: Hypr.PubSub}, + # Start the Finch HTTP client for sending emails + {Finch, name: Hypr.Finch}, + # Start a worker by calling: Hypr.Worker.start_link(arg) + # {Hypr.Worker, arg}, + # Start to serve requests, typically the last entry + HyprWeb.Endpoint + ] + + # See https://hexdocs.pm/elixir/Supervisor.html + # for other strategies and supported options + opts = [strategy: :one_for_one, name: Hypr.Supervisor] + Supervisor.start_link(children, opts) + end + + # Tell Phoenix to update the endpoint configuration + # whenever the application is updated. + @impl true + def config_change(changed, _new, removed) do + HyprWeb.Endpoint.config_change(changed, removed) + :ok + end +end diff --git a/server/lib/hypr/mailer.ex b/server/lib/hypr/mailer.ex new file mode 100644 index 0000000000..ecc9332d35 --- /dev/null +++ b/server/lib/hypr/mailer.ex @@ -0,0 +1,3 @@ +defmodule Hypr.Mailer do + use Swoosh.Mailer, otp_app: :hypr +end diff --git a/server/lib/hypr/repo.ex b/server/lib/hypr/repo.ex new file mode 100644 index 0000000000..41f251167c --- /dev/null +++ b/server/lib/hypr/repo.ex @@ -0,0 +1,5 @@ +defmodule Hypr.Repo do + use Ecto.Repo, + otp_app: :hypr, + adapter: Ecto.Adapters.Postgres +end diff --git a/server/lib/hypr_web.ex b/server/lib/hypr_web.ex new file mode 100644 index 0000000000..db018f8698 --- /dev/null +++ b/server/lib/hypr_web.ex @@ -0,0 +1,113 @@ +defmodule HyprWeb do + @moduledoc """ + The entrypoint for defining your web interface, such + as controllers, components, channels, and so on. + + This can be used in your application as: + + use HyprWeb, :controller + use HyprWeb, :html + + The definitions below will be executed for every controller, + component, etc, so keep them short and clean, focused + on imports, uses and aliases. + + Do NOT define functions inside the quoted expressions + below. Instead, define additional modules and import + those modules here. + """ + + def static_paths, do: ~w(assets fonts images favicon.ico robots.txt) + + def router do + quote do + use Phoenix.Router, helpers: false + + # Import common connection and controller functions to use in pipelines + import Plug.Conn + import Phoenix.Controller + import Phoenix.LiveView.Router + end + end + + def channel do + quote do + use Phoenix.Channel + end + end + + def controller do + quote do + use Phoenix.Controller, + formats: [:html, :json], + layouts: [html: HyprWeb.Layouts] + + import Plug.Conn + import HyprWeb.Gettext + + unquote(verified_routes()) + end + end + + def live_view do + quote do + use Phoenix.LiveView, + layout: {HyprWeb.Layouts, :app} + + unquote(html_helpers()) + end + end + + def live_component do + quote do + use Phoenix.LiveComponent + + unquote(html_helpers()) + end + end + + def html do + quote do + use Phoenix.Component + + # Import convenience functions from controllers + import Phoenix.Controller, + only: [get_csrf_token: 0, view_module: 1, view_template: 1] + + # Include general helpers for rendering HTML + unquote(html_helpers()) + end + end + + defp html_helpers do + quote do + # HTML escaping functionality + import Phoenix.HTML + # Core UI components and translation + import HyprWeb.CoreComponents + import HyprWeb.Gettext + + # Shortcut for generating JS commands + alias Phoenix.LiveView.JS + + # Routes generation with the ~p sigil + unquote(verified_routes()) + end + end + + def verified_routes do + quote do + use Phoenix.VerifiedRoutes, + endpoint: HyprWeb.Endpoint, + router: HyprWeb.Router, + statics: HyprWeb.static_paths() + end + end + + @doc """ + When used, dispatch to the appropriate controller/live_view/etc. + """ + defmacro __using__(which) when is_atom(which) do + apply(__MODULE__, which, []) + end +end diff --git a/server/lib/hypr_web/components/core_components.ex b/server/lib/hypr_web/components/core_components.ex new file mode 100644 index 0000000000..4161569e7d --- /dev/null +++ b/server/lib/hypr_web/components/core_components.ex @@ -0,0 +1,676 @@ +defmodule HyprWeb.CoreComponents do + @moduledoc """ + Provides core UI components. + + At first glance, this module may seem daunting, but its goal is to provide + core building blocks for your application, such as modals, tables, and + forms. The components consist mostly of markup and are well-documented + with doc strings and declarative assigns. You may customize and style + them in any way you want, based on your application growth and needs. + + The default components use Tailwind CSS, a utility-first CSS framework. + See the [Tailwind CSS documentation](https://tailwindcss.com) to learn + how to customize them or feel free to swap in another framework altogether. + + Icons are provided by [heroicons](https://heroicons.com). See `icon/1` for usage. + """ + use Phoenix.Component + + alias Phoenix.LiveView.JS + import HyprWeb.Gettext + + @doc """ + Renders a modal. + + ## Examples + + <.modal id="confirm-modal"> + This is a modal. + + + JS commands may be passed to the `:on_cancel` to configure + the closing/cancel event, for example: + + <.modal id="confirm" on_cancel={JS.navigate(~p"/posts")}> + This is another modal. + + + """ + attr :id, :string, required: true + attr :show, :boolean, default: false + attr :on_cancel, JS, default: %JS{} + slot :inner_block, required: true + + def modal(assigns) do + ~H""" + + """ + end + + def input(%{type: "select"} = assigns) do + ~H""" +
+ <.label for={@id}><%= @label %> + + <.error :for={msg <- @errors}><%= msg %> +
+ """ + end + + def input(%{type: "textarea"} = assigns) do + ~H""" +
+ <.label for={@id}><%= @label %> + + <.error :for={msg <- @errors}><%= msg %> +
+ """ + end + + # All other inputs text, datetime-local, url, password, etc. are handled here... + def input(assigns) do + ~H""" +
+ <.label for={@id}><%= @label %> + + <.error :for={msg <- @errors}><%= msg %> +
+ """ + end + + @doc """ + Renders a label. + """ + attr :for, :string, default: nil + slot :inner_block, required: true + + def label(assigns) do + ~H""" + + """ + end + + @doc """ + Generates a generic error message. + """ + slot :inner_block, required: true + + def error(assigns) do + ~H""" +

+ <.icon name="hero-exclamation-circle-mini" class="mt-0.5 h-5 w-5 flex-none" /> + <%= render_slot(@inner_block) %> +

+ """ + end + + @doc """ + Renders a header with title. + """ + attr :class, :string, default: nil + + slot :inner_block, required: true + slot :subtitle + slot :actions + + def header(assigns) do + ~H""" +
+
+

+ <%= render_slot(@inner_block) %> +

+

+ <%= render_slot(@subtitle) %> +

+
+
<%= render_slot(@actions) %>
+
+ """ + end + + @doc ~S""" + Renders a table with generic styling. + + ## Examples + + <.table id="users" rows={@users}> + <:col :let={user} label="id"><%= user.id %> + <:col :let={user} label="username"><%= user.username %> + + """ + attr :id, :string, required: true + attr :rows, :list, required: true + attr :row_id, :any, default: nil, doc: "the function for generating the row id" + attr :row_click, :any, default: nil, doc: "the function for handling phx-click on each row" + + attr :row_item, :any, + default: &Function.identity/1, + doc: "the function for mapping each row before calling the :col and :action slots" + + slot :col, required: true do + attr :label, :string + end + + slot :action, doc: "the slot for showing user actions in the last table column" + + def table(assigns) do + assigns = + with %{rows: %Phoenix.LiveView.LiveStream{}} <- assigns do + assign(assigns, row_id: assigns.row_id || fn {id, _item} -> id end) + end + + ~H""" +
+ + + + + + + + + + + + + +
<%= col[:label] %> + <%= gettext("Actions") %> +
+
+ + + <%= render_slot(col, @row_item.(row)) %> + +
+
+
+ + + <%= render_slot(action, @row_item.(row)) %> + +
+
+
+ """ + end + + @doc """ + Renders a data list. + + ## Examples + + <.list> + <:item title="Title"><%= @post.title %> + <:item title="Views"><%= @post.views %> + + """ + slot :item, required: true do + attr :title, :string, required: true + end + + def list(assigns) do + ~H""" +
+
+
+
<%= item.title %>
+
<%= render_slot(item) %>
+
+
+
+ """ + end + + @doc """ + Renders a back navigation link. + + ## Examples + + <.back navigate={~p"/posts"}>Back to posts + """ + attr :navigate, :any, required: true + slot :inner_block, required: true + + def back(assigns) do + ~H""" +
+ <.link + navigate={@navigate} + class="text-sm font-semibold leading-6 text-zinc-900 hover:text-zinc-700" + > + <.icon name="hero-arrow-left-solid" class="h-3 w-3" /> + <%= render_slot(@inner_block) %> + +
+ """ + end + + @doc """ + Renders a [Heroicon](https://heroicons.com). + + Heroicons come in three styles – outline, solid, and mini. + By default, the outline style is used, but solid and mini may + be applied by using the `-solid` and `-mini` suffix. + + You can customize the size and colors of the icons by setting + width, height, and background color classes. + + Icons are extracted from the `deps/heroicons` directory and bundled within + your compiled app.css by the plugin in your `assets/tailwind.config.js`. + + ## Examples + + <.icon name="hero-x-mark-solid" /> + <.icon name="hero-arrow-path" class="ml-1 w-3 h-3 animate-spin" /> + """ + attr :name, :string, required: true + attr :class, :string, default: nil + + def icon(%{name: "hero-" <> _} = assigns) do + ~H""" + + """ + end + + ## JS Commands + + def show(js \\ %JS{}, selector) do + JS.show(js, + to: selector, + time: 300, + transition: + {"transition-all transform ease-out duration-300", + "opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95", + "opacity-100 translate-y-0 sm:scale-100"} + ) + end + + def hide(js \\ %JS{}, selector) do + JS.hide(js, + to: selector, + time: 200, + transition: + {"transition-all transform ease-in duration-200", + "opacity-100 translate-y-0 sm:scale-100", + "opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"} + ) + end + + def show_modal(js \\ %JS{}, id) when is_binary(id) do + js + |> JS.show(to: "##{id}") + |> JS.show( + to: "##{id}-bg", + time: 300, + transition: {"transition-all transform ease-out duration-300", "opacity-0", "opacity-100"} + ) + |> show("##{id}-container") + |> JS.add_class("overflow-hidden", to: "body") + |> JS.focus_first(to: "##{id}-content") + end + + def hide_modal(js \\ %JS{}, id) do + js + |> JS.hide( + to: "##{id}-bg", + transition: {"transition-all transform ease-in duration-200", "opacity-100", "opacity-0"} + ) + |> hide("##{id}-container") + |> JS.hide(to: "##{id}", transition: {"block", "block", "hidden"}) + |> JS.remove_class("overflow-hidden", to: "body") + |> JS.pop_focus() + end + + @doc """ + Translates an error message using gettext. + """ + def translate_error({msg, opts}) do + # When using gettext, we typically pass the strings we want + # to translate as a static argument: + # + # # Translate the number of files with plural rules + # dngettext("errors", "1 file", "%{count} files", count) + # + # However the error messages in our forms and APIs are generated + # dynamically, so we need to translate them by calling Gettext + # with our gettext backend as first argument. Translations are + # available in the errors.po file (as we use the "errors" domain). + if count = opts[:count] do + Gettext.dngettext(HyprWeb.Gettext, "errors", msg, msg, count, opts) + else + Gettext.dgettext(HyprWeb.Gettext, "errors", msg, opts) + end + end + + @doc """ + Translates the errors for a field from a keyword list of errors. + """ + def translate_errors(errors, field) when is_list(errors) do + for {^field, {msg, opts}} <- errors, do: translate_error({msg, opts}) + end +end diff --git a/server/lib/hypr_web/components/layouts.ex b/server/lib/hypr_web/components/layouts.ex new file mode 100644 index 0000000000..064d8bb917 --- /dev/null +++ b/server/lib/hypr_web/components/layouts.ex @@ -0,0 +1,14 @@ +defmodule HyprWeb.Layouts do + @moduledoc """ + This module holds different layouts used by your application. + + See the `layouts` directory for all templates available. + The "root" layout is a skeleton rendered as part of the + application router. The "app" layout is set as the default + layout on both `use HyprWeb, :controller` and + `use HyprWeb, :live_view`. + """ + use HyprWeb, :html + + embed_templates "layouts/*" +end diff --git a/server/lib/hypr_web/components/layouts/app.html.heex b/server/lib/hypr_web/components/layouts/app.html.heex new file mode 100644 index 0000000000..e23bfc81c4 --- /dev/null +++ b/server/lib/hypr_web/components/layouts/app.html.heex @@ -0,0 +1,32 @@ +
+
+
+ + + +

+ v<%= Application.spec(:phoenix, :vsn) %> +

+
+ +
+
+
+
+ <.flash_group flash={@flash} /> + <%= @inner_content %> +
+
diff --git a/server/lib/hypr_web/components/layouts/root.html.heex b/server/lib/hypr_web/components/layouts/root.html.heex new file mode 100644 index 0000000000..d4c396f8f1 --- /dev/null +++ b/server/lib/hypr_web/components/layouts/root.html.heex @@ -0,0 +1,17 @@ + + + + + + + <.live_title suffix=" · Phoenix Framework"> + <%= assigns[:page_title] || "Hypr" %> + + + + + + <%= @inner_content %> + + diff --git a/server/lib/hypr_web/controllers/error_html.ex b/server/lib/hypr_web/controllers/error_html.ex new file mode 100644 index 0000000000..82d7f97acf --- /dev/null +++ b/server/lib/hypr_web/controllers/error_html.ex @@ -0,0 +1,24 @@ +defmodule HyprWeb.ErrorHTML do + @moduledoc """ + This module is invoked by your endpoint in case of errors on HTML requests. + + See config/config.exs. + """ + use HyprWeb, :html + + # If you want to customize your error pages, + # uncomment the embed_templates/1 call below + # and add pages to the error directory: + # + # * lib/hypr_web/controllers/error_html/404.html.heex + # * lib/hypr_web/controllers/error_html/500.html.heex + # + # embed_templates "error_html/*" + + # The default is to render a plain text page based on + # the template name. For example, "404.html" becomes + # "Not Found". + def render(template, _assigns) do + Phoenix.Controller.status_message_from_template(template) + end +end diff --git a/server/lib/hypr_web/controllers/error_json.ex b/server/lib/hypr_web/controllers/error_json.ex new file mode 100644 index 0000000000..47ea640d79 --- /dev/null +++ b/server/lib/hypr_web/controllers/error_json.ex @@ -0,0 +1,21 @@ +defmodule HyprWeb.ErrorJSON do + @moduledoc """ + This module is invoked by your endpoint in case of errors on JSON requests. + + See config/config.exs. + """ + + # If you want to customize a particular status code, + # you may add your own clauses, such as: + # + # def render("500.json", _assigns) do + # %{errors: %{detail: "Internal Server Error"}} + # end + + # By default, Phoenix returns the status message from + # the template name. For example, "404.json" becomes + # "Not Found". + def render(template, _assigns) do + %{errors: %{detail: Phoenix.Controller.status_message_from_template(template)}} + end +end diff --git a/server/lib/hypr_web/controllers/page_controller.ex b/server/lib/hypr_web/controllers/page_controller.ex new file mode 100644 index 0000000000..e19919ad65 --- /dev/null +++ b/server/lib/hypr_web/controllers/page_controller.ex @@ -0,0 +1,9 @@ +defmodule HyprWeb.PageController do + use HyprWeb, :controller + + def home(conn, _params) do + # The home page is often custom made, + # so skip the default app layout. + render(conn, :home, layout: false) + end +end diff --git a/server/lib/hypr_web/controllers/page_html.ex b/server/lib/hypr_web/controllers/page_html.ex new file mode 100644 index 0000000000..21933b416d --- /dev/null +++ b/server/lib/hypr_web/controllers/page_html.ex @@ -0,0 +1,10 @@ +defmodule HyprWeb.PageHTML do + @moduledoc """ + This module contains pages rendered by PageController. + + See the `page_html` directory for all templates available. + """ + use HyprWeb, :html + + embed_templates "page_html/*" +end diff --git a/server/lib/hypr_web/controllers/page_html/home.html.heex b/server/lib/hypr_web/controllers/page_html/home.html.heex new file mode 100644 index 0000000000..dc1820b11e --- /dev/null +++ b/server/lib/hypr_web/controllers/page_html/home.html.heex @@ -0,0 +1,222 @@ +<.flash_group flash={@flash} /> + +
+
+ +

+ Phoenix Framework + + v<%= Application.spec(:phoenix, :vsn) %> + +

+

+ Peace of mind from prototype to production. +

+

+ Build rich, interactive web applications quickly, with less code and fewer moving parts. Join our growing community of developers using Phoenix to craft APIs, HTML5 apps and more, for fun or at scale. +

+ +
+
diff --git a/server/lib/hypr_web/endpoint.ex b/server/lib/hypr_web/endpoint.ex new file mode 100644 index 0000000000..a655c457d2 --- /dev/null +++ b/server/lib/hypr_web/endpoint.ex @@ -0,0 +1,49 @@ +defmodule HyprWeb.Endpoint do + use Phoenix.Endpoint, otp_app: :hypr + + # The session will be stored in the cookie and signed, + # this means its contents can be read but not tampered with. + # Set :encryption_salt if you would also like to encrypt it. + @session_options [ + store: :cookie, + key: "_hypr_key", + signing_salt: "MWJdmtgb", + same_site: "Lax" + ] + + socket "/live", Phoenix.LiveView.Socket, + websocket: [connect_info: [session: @session_options]], + longpoll: [connect_info: [session: @session_options]] + + # Serve at "/" the static files from "priv/static" directory. + # + # You should set gzip to true if you are running phx.digest + # when deploying your static files in production. + plug Plug.Static, + at: "/", + from: :hypr, + gzip: false, + only: HyprWeb.static_paths() + + # Code reloading can be explicitly enabled under the + # :code_reloader configuration of your endpoint. + if code_reloading? do + socket "/phoenix/live_reload/socket", Phoenix.LiveReloader.Socket + plug Phoenix.LiveReloader + plug Phoenix.CodeReloader + plug Phoenix.Ecto.CheckRepoStatus, otp_app: :hypr + end + + plug Plug.RequestId + plug Plug.Telemetry, event_prefix: [:phoenix, :endpoint] + + plug Plug.Parsers, + parsers: [:urlencoded, :multipart, :json], + pass: ["*/*"], + json_decoder: Phoenix.json_library() + + plug Plug.MethodOverride + plug Plug.Head + plug Plug.Session, @session_options + plug HyprWeb.Router +end diff --git a/server/lib/hypr_web/gettext.ex b/server/lib/hypr_web/gettext.ex new file mode 100644 index 0000000000..282d7bded8 --- /dev/null +++ b/server/lib/hypr_web/gettext.ex @@ -0,0 +1,24 @@ +defmodule HyprWeb.Gettext do + @moduledoc """ + A module providing Internationalization with a gettext-based API. + + By using [Gettext](https://hexdocs.pm/gettext), + your module gains a set of macros for translations, for example: + + import HyprWeb.Gettext + + # Simple translation + gettext("Here is the string to translate") + + # Plural translation + ngettext("Here is the string to translate", + "Here are the strings to translate", + 3) + + # Domain-based translation + dgettext("errors", "Here is the error message to translate") + + See the [Gettext Docs](https://hexdocs.pm/gettext) for detailed usage. + """ + use Gettext, otp_app: :hypr +end diff --git a/server/lib/hypr_web/router.ex b/server/lib/hypr_web/router.ex new file mode 100644 index 0000000000..d8925492a6 --- /dev/null +++ b/server/lib/hypr_web/router.ex @@ -0,0 +1,37 @@ +defmodule HyprWeb.Router do + use HyprWeb, :router + + pipeline :browser do + plug :accepts, ["html"] + plug :fetch_session + plug :fetch_live_flash + plug :put_root_layout, html: {HyprWeb.Layouts, :root} + plug :protect_from_forgery + plug :put_secure_browser_headers + end + + pipeline :api do + plug :accepts, ["json"] + end + + scope "/", HyprWeb do + pipe_through :browser + + get "/", PageController, :home + end + + # Other scopes may use custom stacks. + # scope "/api", HyprWeb do + # pipe_through :api + # end + + # Enable Swoosh mailbox preview in development + if Application.compile_env(:hypr, :dev_routes) do + + scope "/dev" do + pipe_through :browser + + forward "/mailbox", Plug.Swoosh.MailboxPreview + end + end +end diff --git a/server/lib/hypr_web/telemetry.ex b/server/lib/hypr_web/telemetry.ex new file mode 100644 index 0000000000..fcde974181 --- /dev/null +++ b/server/lib/hypr_web/telemetry.ex @@ -0,0 +1,92 @@ +defmodule HyprWeb.Telemetry do + use Supervisor + import Telemetry.Metrics + + def start_link(arg) do + Supervisor.start_link(__MODULE__, arg, name: __MODULE__) + end + + @impl true + def init(_arg) do + children = [ + # Telemetry poller will execute the given period measurements + # every 10_000ms. Learn more here: https://hexdocs.pm/telemetry_metrics + {:telemetry_poller, measurements: periodic_measurements(), period: 10_000} + # Add reporters as children of your supervision tree. + # {Telemetry.Metrics.ConsoleReporter, metrics: metrics()} + ] + + Supervisor.init(children, strategy: :one_for_one) + end + + def metrics do + [ + # Phoenix Metrics + summary("phoenix.endpoint.start.system_time", + unit: {:native, :millisecond} + ), + summary("phoenix.endpoint.stop.duration", + unit: {:native, :millisecond} + ), + summary("phoenix.router_dispatch.start.system_time", + tags: [:route], + unit: {:native, :millisecond} + ), + summary("phoenix.router_dispatch.exception.duration", + tags: [:route], + unit: {:native, :millisecond} + ), + summary("phoenix.router_dispatch.stop.duration", + tags: [:route], + unit: {:native, :millisecond} + ), + summary("phoenix.socket_connected.duration", + unit: {:native, :millisecond} + ), + summary("phoenix.channel_joined.duration", + unit: {:native, :millisecond} + ), + summary("phoenix.channel_handled_in.duration", + tags: [:event], + unit: {:native, :millisecond} + ), + + # Database Metrics + summary("hypr.repo.query.total_time", + unit: {:native, :millisecond}, + description: "The sum of the other measurements" + ), + summary("hypr.repo.query.decode_time", + unit: {:native, :millisecond}, + description: "The time spent decoding the data received from the database" + ), + summary("hypr.repo.query.query_time", + unit: {:native, :millisecond}, + description: "The time spent executing the query" + ), + summary("hypr.repo.query.queue_time", + unit: {:native, :millisecond}, + description: "The time spent waiting for a database connection" + ), + summary("hypr.repo.query.idle_time", + unit: {:native, :millisecond}, + description: + "The time the connection spent waiting before being checked out for the query" + ), + + # VM Metrics + summary("vm.memory.total", unit: {:byte, :kilobyte}), + summary("vm.total_run_queue_lengths.total"), + summary("vm.total_run_queue_lengths.cpu"), + summary("vm.total_run_queue_lengths.io") + ] + end + + defp periodic_measurements do + [ + # A module, function and arguments to be invoked periodically. + # This function must call :telemetry.execute/3 and a metric must be added above. + # {HyprWeb, :count_users, []} + ] + end +end diff --git a/server/mix.exs b/server/mix.exs new file mode 100644 index 0000000000..5ebac6010e --- /dev/null +++ b/server/mix.exs @@ -0,0 +1,85 @@ +defmodule Hypr.MixProject do + use Mix.Project + + def project do + [ + app: :hypr, + version: "0.1.0", + elixir: "~> 1.14", + elixirc_paths: elixirc_paths(Mix.env()), + start_permanent: Mix.env() == :prod, + aliases: aliases(), + deps: deps() + ] + end + + # Configuration for the OTP application. + # + # Type `mix help compile.app` for more information. + def application do + [ + mod: {Hypr.Application, []}, + extra_applications: [:logger, :runtime_tools] + ] + end + + # Specifies which paths to compile per environment. + defp elixirc_paths(:test), do: ["lib", "test/support"] + defp elixirc_paths(_), do: ["lib"] + + # Specifies your project dependencies. + # + # Type `mix help deps` for examples and options. + defp deps do + [ + {:phoenix, "~> 1.7.14"}, + {:phoenix_ecto, "~> 4.5"}, + {:ecto_sql, "~> 3.10"}, + {:postgrex, ">= 0.0.0"}, + {:phoenix_html, "~> 4.1"}, + {:phoenix_live_reload, "~> 1.2", only: :dev}, + # TODO bump on release to {:phoenix_live_view, "~> 1.0.0"}, + {:phoenix_live_view, "~> 1.0.0-rc.1", override: true}, + {:floki, ">= 0.30.0", only: :test}, + {:esbuild, "~> 0.8", runtime: Mix.env() == :dev}, + {:tailwind, "~> 0.2", runtime: Mix.env() == :dev}, + {:heroicons, + github: "tailwindlabs/heroicons", + tag: "v2.1.1", + sparse: "optimized", + app: false, + compile: false, + depth: 1}, + {:swoosh, "~> 1.5"}, + {:finch, "~> 0.13"}, + {:telemetry_metrics, "~> 1.0"}, + {:telemetry_poller, "~> 1.0"}, + {:gettext, "~> 0.20"}, + {:jason, "~> 1.2"}, + {:dns_cluster, "~> 0.1.1"}, + {:bandit, "~> 1.5"} + ] + end + + # Aliases are shortcuts or tasks specific to the current project. + # For example, to install project dependencies and perform other setup tasks, run: + # + # $ mix setup + # + # See the documentation for `Mix` for more info on aliases. + defp aliases do + [ + setup: ["deps.get", "ecto.setup", "assets.setup", "assets.build"], + "ecto.setup": ["ecto.create", "ecto.migrate", "run priv/repo/seeds.exs"], + "ecto.reset": ["ecto.drop", "ecto.setup"], + test: ["ecto.create --quiet", "ecto.migrate --quiet", "test"], + "assets.setup": ["tailwind.install --if-missing", "esbuild.install --if-missing"], + "assets.build": ["tailwind hypr", "esbuild hypr"], + "assets.deploy": [ + "tailwind hypr --minify", + "esbuild hypr --minify", + "phx.digest" + ] + ] + end +end diff --git a/server/mix.lock b/server/mix.lock new file mode 100644 index 0000000000..b984fed552 --- /dev/null +++ b/server/mix.lock @@ -0,0 +1,40 @@ +%{ + "bandit": {:hex, :bandit, "1.6.1", "9e01b93d72ddc21d8c576a704949e86ee6cde7d11270a1d3073787876527a48f", [:mix], [{:hpax, "~> 1.0", [hex: :hpax, repo: "hexpm", optional: false]}, {:plug, "~> 1.14", [hex: :plug, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}, {:thousand_island, "~> 1.0", [hex: :thousand_island, repo: "hexpm", optional: false]}, {:websock, "~> 0.5", [hex: :websock, repo: "hexpm", optional: false]}], "hexpm", "5a904bf010ea24b67979835e0507688e31ac873d4ffc8ed0e5413e8d77455031"}, + "castore": {:hex, :castore, "1.0.10", "43bbeeac820f16c89f79721af1b3e092399b3a1ecc8df1a472738fd853574911", [:mix], [], "hexpm", "1b0b7ea14d889d9ea21202c43a4fa015eb913021cb535e8ed91946f4b77a8848"}, + "db_connection": {:hex, :db_connection, "2.7.0", "b99faa9291bb09892c7da373bb82cba59aefa9b36300f6145c5f201c7adf48ec", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "dcf08f31b2701f857dfc787fbad78223d61a32204f217f15e881dd93e4bdd3ff"}, + "decimal": {:hex, :decimal, "2.3.0", "3ad6255aa77b4a3c4f818171b12d237500e63525c2fd056699967a3e7ea20f62", [:mix], [], "hexpm", "a4d66355cb29cb47c3cf30e71329e58361cfcb37c34235ef3bf1d7bf3773aeac"}, + "dns_cluster": {:hex, :dns_cluster, "0.1.3", "0bc20a2c88ed6cc494f2964075c359f8c2d00e1bf25518a6a6c7fd277c9b0c66", [:mix], [], "hexpm", "46cb7c4a1b3e52c7ad4cbe33ca5079fbde4840dedeafca2baf77996c2da1bc33"}, + "ecto": {:hex, :ecto, "3.12.5", "4a312960ce612e17337e7cefcf9be45b95a3be6b36b6f94dfb3d8c361d631866", [:mix], [{:decimal, "~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "6eb18e80bef8bb57e17f5a7f068a1719fbda384d40fc37acb8eb8aeca493b6ea"}, + "ecto_sql": {:hex, :ecto_sql, "3.12.1", "c0d0d60e85d9ff4631f12bafa454bc392ce8b9ec83531a412c12a0d415a3a4d0", [:mix], [{:db_connection, "~> 2.4.1 or ~> 2.5", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.12", [hex: :ecto, repo: "hexpm", optional: false]}, {:myxql, "~> 0.7", [hex: :myxql, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.19 or ~> 1.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:tds, "~> 2.1.1 or ~> 2.2", [hex: :tds, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.0 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "aff5b958a899762c5f09028c847569f7dfb9cc9d63bdb8133bff8a5546de6bf5"}, + "esbuild": {:hex, :esbuild, "0.8.2", "5f379dfa383ef482b738e7771daf238b2d1cfb0222bef9d3b20d4c8f06c7a7ac", [:mix], [{:castore, ">= 0.0.0", [hex: :castore, repo: "hexpm", optional: false]}, {:jason, "~> 1.4", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "558a8a08ed78eb820efbfda1de196569d8bfa9b51e8371a1934fbb31345feda7"}, + "expo": {:hex, :expo, "1.1.0", "f7b9ed7fb5745ebe1eeedf3d6f29226c5dd52897ac67c0f8af62a07e661e5c75", [:mix], [], "hexpm", "fbadf93f4700fb44c331362177bdca9eeb8097e8b0ef525c9cc501cb9917c960"}, + "file_system": {:hex, :file_system, "1.0.1", "79e8ceaddb0416f8b8cd02a0127bdbababe7bf4a23d2a395b983c1f8b3f73edd", [:mix], [], "hexpm", "4414d1f38863ddf9120720cd976fce5bdde8e91d8283353f0e31850fa89feb9e"}, + "finch": {:hex, :finch, "0.19.0", "c644641491ea854fc5c1bbaef36bfc764e3f08e7185e1f084e35e0672241b76d", [:mix], [{:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:mint, "~> 1.6.2 or ~> 1.7", [hex: :mint, repo: "hexpm", optional: false]}, {:nimble_options, "~> 0.4 or ~> 1.0", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:nimble_pool, "~> 1.1", [hex: :nimble_pool, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "fc5324ce209125d1e2fa0fcd2634601c52a787aff1cd33ee833664a5af4ea2b6"}, + "floki": {:hex, :floki, "0.37.0", "b83e0280bbc6372f2a403b2848013650b16640cd2470aea6701f0632223d719e", [:mix], [], "hexpm", "516a0c15a69f78c47dc8e0b9b3724b29608aa6619379f91b1ffa47109b5d0dd3"}, + "gettext": {:hex, :gettext, "0.26.2", "5978aa7b21fada6deabf1f6341ddba50bc69c999e812211903b169799208f2a8", [:mix], [{:expo, "~> 0.5.1 or ~> 1.0", [hex: :expo, repo: "hexpm", optional: false]}], "hexpm", "aa978504bcf76511efdc22d580ba08e2279caab1066b76bb9aa81c4a1e0a32a5"}, + "heroicons": {:git, "https://github.com/tailwindlabs/heroicons.git", "88ab3a0d790e6a47404cba02800a6b25d2afae50", [tag: "v2.1.1", sparse: "optimized", depth: 1]}, + "hpax": {:hex, :hpax, "1.0.1", "c857057f89e8bd71d97d9042e009df2a42705d6d690d54eca84c8b29af0787b0", [:mix], [], "hexpm", "4e2d5a4f76ae1e3048f35ae7adb1641c36265510a2d4638157fbcb53dda38445"}, + "jason": {:hex, :jason, "1.4.4", "b9226785a9aa77b6857ca22832cffa5d5011a667207eb2a0ad56adb5db443b8a", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "c5eb0cab91f094599f94d55bc63409236a8ec69a21a67814529e8d5f6cc90b3b"}, + "mime": {:hex, :mime, "2.0.6", "8f18486773d9b15f95f4f4f1e39b710045fa1de891fada4516559967276e4dc2", [:mix], [], "hexpm", "c9945363a6b26d747389aac3643f8e0e09d30499a138ad64fe8fd1d13d9b153e"}, + "mint": {:hex, :mint, "1.6.2", "af6d97a4051eee4f05b5500671d47c3a67dac7386045d87a904126fd4bbcea2e", [:mix], [{:castore, "~> 0.1.0 or ~> 1.0", [hex: :castore, repo: "hexpm", optional: true]}, {:hpax, "~> 0.1.1 or ~> 0.2.0 or ~> 1.0", [hex: :hpax, repo: "hexpm", optional: false]}], "hexpm", "5ee441dffc1892f1ae59127f74afe8fd82fda6587794278d924e4d90ea3d63f9"}, + "nimble_options": {:hex, :nimble_options, "1.1.1", "e3a492d54d85fc3fd7c5baf411d9d2852922f66e69476317787a7b2bb000a61b", [:mix], [], "hexpm", "821b2470ca9442c4b6984882fe9bb0389371b8ddec4d45a9504f00a66f650b44"}, + "nimble_pool": {:hex, :nimble_pool, "1.1.0", "bf9c29fbdcba3564a8b800d1eeb5a3c58f36e1e11d7b7fb2e084a643f645f06b", [:mix], [], "hexpm", "af2e4e6b34197db81f7aad230c1118eac993acc0dae6bc83bac0126d4ae0813a"}, + "phoenix": {:hex, :phoenix, "1.7.18", "5310c21443514be44ed93c422e15870aef254cf1b3619e4f91538e7529d2b2e4", [:mix], [{:castore, ">= 0.0.0", [hex: :castore, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 2.1", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}, {:phoenix_template, "~> 1.0", [hex: :phoenix_template, repo: "hexpm", optional: false]}, {:phoenix_view, "~> 2.0", [hex: :phoenix_view, repo: "hexpm", optional: true]}, {:plug, "~> 1.14", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 2.7", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:plug_crypto, "~> 1.2 or ~> 2.0", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}, {:websock_adapter, "~> 0.5.3", [hex: :websock_adapter, repo: "hexpm", optional: false]}], "hexpm", "1797fcc82108442a66f2c77a643a62980f342bfeb63d6c9a515ab8294870004e"}, + "phoenix_ecto": {:hex, :phoenix_ecto, "4.6.3", "f686701b0499a07f2e3b122d84d52ff8a31f5def386e03706c916f6feddf69ef", [:mix], [{:ecto, "~> 3.5", [hex: :ecto, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 2.14.2 or ~> 3.0 or ~> 4.1", [hex: :phoenix_html, repo: "hexpm", optional: true]}, {:plug, "~> 1.9", [hex: :plug, repo: "hexpm", optional: false]}, {:postgrex, "~> 0.16 or ~> 1.0", [hex: :postgrex, repo: "hexpm", optional: true]}], "hexpm", "909502956916a657a197f94cc1206d9a65247538de8a5e186f7537c895d95764"}, + "phoenix_html": {:hex, :phoenix_html, "4.1.1", "4c064fd3873d12ebb1388425a8f2a19348cef56e7289e1998e2d2fa758aa982e", [:mix], [], "hexpm", "f2f2df5a72bc9a2f510b21497fd7d2b86d932ec0598f0210fed4114adc546c6f"}, + "phoenix_live_reload": {:hex, :phoenix_live_reload, "1.5.3", "f2161c207fda0e4fb55165f650f7f8db23f02b29e3bff00ff7ef161d6ac1f09d", [:mix], [{:file_system, "~> 0.3 or ~> 1.0", [hex: :file_system, repo: "hexpm", optional: false]}, {:phoenix, "~> 1.4", [hex: :phoenix, repo: "hexpm", optional: false]}], "hexpm", "b4ec9cd73cb01ff1bd1cac92e045d13e7030330b74164297d1aee3907b54803c"}, + "phoenix_live_view": {:hex, :phoenix_live_view, "1.0.1", "5389a30658176c0de816636ce276567478bffd063c082515a6e8368b8fc9a0db", [:mix], [{:floki, "~> 0.36", [hex: :floki, repo: "hexpm", optional: true]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix, "~> 1.6.15 or ~> 1.7.0", [hex: :phoenix, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 3.3 or ~> 4.0", [hex: :phoenix_html, repo: "hexpm", optional: false]}, {:phoenix_template, "~> 1.0", [hex: :phoenix_template, repo: "hexpm", optional: false]}, {:phoenix_view, "~> 2.0", [hex: :phoenix_view, repo: "hexpm", optional: true]}, {:plug, "~> 1.15", [hex: :plug, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.2 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "c0f517e6f290f10dbb94343ac22e0109437fb1fa6f0696e7c73967b789c1c285"}, + "phoenix_pubsub": {:hex, :phoenix_pubsub, "2.1.3", "3168d78ba41835aecad272d5e8cd51aa87a7ac9eb836eabc42f6e57538e3731d", [:mix], [], "hexpm", "bba06bc1dcfd8cb086759f0edc94a8ba2bc8896d5331a1e2c2902bf8e36ee502"}, + "phoenix_template": {:hex, :phoenix_template, "1.0.4", "e2092c132f3b5e5b2d49c96695342eb36d0ed514c5b252a77048d5969330d639", [:mix], [{:phoenix_html, "~> 2.14.2 or ~> 3.0 or ~> 4.0", [hex: :phoenix_html, repo: "hexpm", optional: true]}], "hexpm", "2c0c81f0e5c6753faf5cca2f229c9709919aba34fab866d3bc05060c9c444206"}, + "plug": {:hex, :plug, "1.16.1", "40c74619c12f82736d2214557dedec2e9762029b2438d6d175c5074c933edc9d", [:mix], [{:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.1.1 or ~> 1.2 or ~> 2.0", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.3 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "a13ff6b9006b03d7e33874945b2755253841b238c34071ed85b0e86057f8cddc"}, + "plug_crypto": {:hex, :plug_crypto, "2.1.0", "f44309c2b06d249c27c8d3f65cfe08158ade08418cf540fd4f72d4d6863abb7b", [:mix], [], "hexpm", "131216a4b030b8f8ce0f26038bc4421ae60e4bb95c5cf5395e1421437824c4fa"}, + "postgrex": {:hex, :postgrex, "0.19.3", "a0bda6e3bc75ec07fca5b0a89bffd242ca209a4822a9533e7d3e84ee80707e19", [:mix], [{:db_connection, "~> 2.1", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.5 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:table, "~> 0.1.0", [hex: :table, repo: "hexpm", optional: true]}], "hexpm", "d31c28053655b78f47f948c85bb1cf86a9c1f8ead346ba1aa0d0df017fa05b61"}, + "swoosh": {:hex, :swoosh, "1.17.5", "14910d267a2633d4335917b37846e376e2067815601592629366c39845dad145", [:mix], [{:bandit, ">= 1.0.0", [hex: :bandit, repo: "hexpm", optional: true]}, {:cowboy, "~> 1.1 or ~> 2.4", [hex: :cowboy, repo: "hexpm", optional: true]}, {:ex_aws, "~> 2.1", [hex: :ex_aws, repo: "hexpm", optional: true]}, {:finch, "~> 0.6", [hex: :finch, repo: "hexpm", optional: true]}, {:gen_smtp, "~> 0.13 or ~> 1.0", [hex: :gen_smtp, repo: "hexpm", optional: true]}, {:hackney, "~> 1.9", [hex: :hackney, repo: "hexpm", optional: true]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}, {:mail, "~> 0.2", [hex: :mail, repo: "hexpm", optional: true]}, {:mime, "~> 1.1 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:mua, "~> 0.2.3", [hex: :mua, repo: "hexpm", optional: true]}, {:multipart, "~> 0.4", [hex: :multipart, repo: "hexpm", optional: true]}, {:plug, "~> 1.9", [hex: :plug, repo: "hexpm", optional: true]}, {:plug_cowboy, ">= 1.0.0", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:req, "~> 0.5 or ~> 1.0", [hex: :req, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.2 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "629113d477bc82c4c3bffd15a25e8becc1c7ccc0f0e67743b017caddebb06f04"}, + "tailwind": {:hex, :tailwind, "0.2.4", "5706ec47182d4e7045901302bf3a333e80f3d1af65c442ba9a9eed152fb26c2e", [:mix], [{:castore, ">= 0.0.0", [hex: :castore, repo: "hexpm", optional: false]}], "hexpm", "c6e4a82b8727bab593700c998a4d98cf3d8025678bfde059aed71d0000c3e463"}, + "telemetry": {:hex, :telemetry, "1.3.0", "fedebbae410d715cf8e7062c96a1ef32ec22e764197f70cda73d82778d61e7a2", [:rebar3], [], "hexpm", "7015fc8919dbe63764f4b4b87a95b7c0996bd539e0d499be6ec9d7f3875b79e6"}, + "telemetry_metrics": {:hex, :telemetry_metrics, "1.0.0", "29f5f84991ca98b8eb02fc208b2e6de7c95f8bb2294ef244a176675adc7775df", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "f23713b3847286a534e005126d4c959ebcca68ae9582118ce436b521d1d47d5d"}, + "telemetry_poller": {:hex, :telemetry_poller, "1.1.0", "58fa7c216257291caaf8d05678c8d01bd45f4bdbc1286838a28c4bb62ef32999", [:rebar3], [{:telemetry, "~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "9eb9d9cbfd81cbd7cdd24682f8711b6e2b691289a0de6826e58452f28c103c8f"}, + "thousand_island": {:hex, :thousand_island, "1.3.7", "1da7598c0f4f5f50562c097a3f8af308ded48cd35139f0e6f17d9443e4d0c9c5", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "0139335079953de41d381a6134d8b618d53d084f558c734f2662d1a72818dd12"}, + "websock": {:hex, :websock, "0.5.3", "2f69a6ebe810328555b6fe5c831a851f485e303a7c8ce6c5f675abeb20ebdadc", [:mix], [], "hexpm", "6105453d7fac22c712ad66fab1d45abdf049868f253cf719b625151460b8b453"}, + "websock_adapter": {:hex, :websock_adapter, "0.5.8", "3b97dc94e407e2d1fc666b2fb9acf6be81a1798a2602294aac000260a7c4a47d", [:mix], [{:bandit, ">= 0.6.0", [hex: :bandit, repo: "hexpm", optional: true]}, {:plug, "~> 1.14", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 2.6", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:websock, "~> 0.5", [hex: :websock, repo: "hexpm", optional: false]}], "hexpm", "315b9a1865552212b5f35140ad194e67ce31af45bcee443d4ecb96b5fd3f3782"}, +} diff --git a/server/priv/gettext/en/LC_MESSAGES/errors.po b/server/priv/gettext/en/LC_MESSAGES/errors.po new file mode 100644 index 0000000000..844c4f5cea --- /dev/null +++ b/server/priv/gettext/en/LC_MESSAGES/errors.po @@ -0,0 +1,112 @@ +## `msgid`s in this file come from POT (.pot) files. +## +## Do not add, change, or remove `msgid`s manually here as +## they're tied to the ones in the corresponding POT file +## (with the same domain). +## +## Use `mix gettext.extract --merge` or `mix gettext.merge` +## to merge POT files into PO files. +msgid "" +msgstr "" +"Language: en\n" + +## From Ecto.Changeset.cast/4 +msgid "can't be blank" +msgstr "" + +## From Ecto.Changeset.unique_constraint/3 +msgid "has already been taken" +msgstr "" + +## From Ecto.Changeset.put_change/3 +msgid "is invalid" +msgstr "" + +## From Ecto.Changeset.validate_acceptance/3 +msgid "must be accepted" +msgstr "" + +## From Ecto.Changeset.validate_format/3 +msgid "has invalid format" +msgstr "" + +## From Ecto.Changeset.validate_subset/3 +msgid "has an invalid entry" +msgstr "" + +## From Ecto.Changeset.validate_exclusion/3 +msgid "is reserved" +msgstr "" + +## From Ecto.Changeset.validate_confirmation/3 +msgid "does not match confirmation" +msgstr "" + +## From Ecto.Changeset.no_assoc_constraint/3 +msgid "is still associated with this entry" +msgstr "" + +msgid "are still associated with this entry" +msgstr "" + +## From Ecto.Changeset.validate_length/3 +msgid "should have %{count} item(s)" +msgid_plural "should have %{count} item(s)" +msgstr[0] "" +msgstr[1] "" + +msgid "should be %{count} character(s)" +msgid_plural "should be %{count} character(s)" +msgstr[0] "" +msgstr[1] "" + +msgid "should be %{count} byte(s)" +msgid_plural "should be %{count} byte(s)" +msgstr[0] "" +msgstr[1] "" + +msgid "should have at least %{count} item(s)" +msgid_plural "should have at least %{count} item(s)" +msgstr[0] "" +msgstr[1] "" + +msgid "should be at least %{count} character(s)" +msgid_plural "should be at least %{count} character(s)" +msgstr[0] "" +msgstr[1] "" + +msgid "should be at least %{count} byte(s)" +msgid_plural "should be at least %{count} byte(s)" +msgstr[0] "" +msgstr[1] "" + +msgid "should have at most %{count} item(s)" +msgid_plural "should have at most %{count} item(s)" +msgstr[0] "" +msgstr[1] "" + +msgid "should be at most %{count} character(s)" +msgid_plural "should be at most %{count} character(s)" +msgstr[0] "" +msgstr[1] "" + +msgid "should be at most %{count} byte(s)" +msgid_plural "should be at most %{count} byte(s)" +msgstr[0] "" +msgstr[1] "" + +## From Ecto.Changeset.validate_number/3 +msgid "must be less than %{number}" +msgstr "" + +msgid "must be greater than %{number}" +msgstr "" + +msgid "must be less than or equal to %{number}" +msgstr "" + +msgid "must be greater than or equal to %{number}" +msgstr "" + +msgid "must be equal to %{number}" +msgstr "" diff --git a/server/priv/gettext/errors.pot b/server/priv/gettext/errors.pot new file mode 100644 index 0000000000..eef2de2ba4 --- /dev/null +++ b/server/priv/gettext/errors.pot @@ -0,0 +1,109 @@ +## This is a PO Template file. +## +## `msgid`s here are often extracted from source code. +## Add new translations manually only if they're dynamic +## translations that can't be statically extracted. +## +## Run `mix gettext.extract` to bring this file up to +## date. Leave `msgstr`s empty as changing them here has no +## effect: edit them in PO (`.po`) files instead. +## From Ecto.Changeset.cast/4 +msgid "can't be blank" +msgstr "" + +## From Ecto.Changeset.unique_constraint/3 +msgid "has already been taken" +msgstr "" + +## From Ecto.Changeset.put_change/3 +msgid "is invalid" +msgstr "" + +## From Ecto.Changeset.validate_acceptance/3 +msgid "must be accepted" +msgstr "" + +## From Ecto.Changeset.validate_format/3 +msgid "has invalid format" +msgstr "" + +## From Ecto.Changeset.validate_subset/3 +msgid "has an invalid entry" +msgstr "" + +## From Ecto.Changeset.validate_exclusion/3 +msgid "is reserved" +msgstr "" + +## From Ecto.Changeset.validate_confirmation/3 +msgid "does not match confirmation" +msgstr "" + +## From Ecto.Changeset.no_assoc_constraint/3 +msgid "is still associated with this entry" +msgstr "" + +msgid "are still associated with this entry" +msgstr "" + +## From Ecto.Changeset.validate_length/3 +msgid "should have %{count} item(s)" +msgid_plural "should have %{count} item(s)" +msgstr[0] "" +msgstr[1] "" + +msgid "should be %{count} character(s)" +msgid_plural "should be %{count} character(s)" +msgstr[0] "" +msgstr[1] "" + +msgid "should be %{count} byte(s)" +msgid_plural "should be %{count} byte(s)" +msgstr[0] "" +msgstr[1] "" + +msgid "should have at least %{count} item(s)" +msgid_plural "should have at least %{count} item(s)" +msgstr[0] "" +msgstr[1] "" + +msgid "should be at least %{count} character(s)" +msgid_plural "should be at least %{count} character(s)" +msgstr[0] "" +msgstr[1] "" + +msgid "should be at least %{count} byte(s)" +msgid_plural "should be at least %{count} byte(s)" +msgstr[0] "" +msgstr[1] "" + +msgid "should have at most %{count} item(s)" +msgid_plural "should have at most %{count} item(s)" +msgstr[0] "" +msgstr[1] "" + +msgid "should be at most %{count} character(s)" +msgid_plural "should be at most %{count} character(s)" +msgstr[0] "" +msgstr[1] "" + +msgid "should be at most %{count} byte(s)" +msgid_plural "should be at most %{count} byte(s)" +msgstr[0] "" +msgstr[1] "" + +## From Ecto.Changeset.validate_number/3 +msgid "must be less than %{number}" +msgstr "" + +msgid "must be greater than %{number}" +msgstr "" + +msgid "must be less than or equal to %{number}" +msgstr "" + +msgid "must be greater than or equal to %{number}" +msgstr "" + +msgid "must be equal to %{number}" +msgstr "" diff --git a/server/priv/repo/migrations/.formatter.exs b/server/priv/repo/migrations/.formatter.exs new file mode 100644 index 0000000000..49f9151ed2 --- /dev/null +++ b/server/priv/repo/migrations/.formatter.exs @@ -0,0 +1,4 @@ +[ + import_deps: [:ecto_sql], + inputs: ["*.exs"] +] diff --git a/server/priv/repo/seeds.exs b/server/priv/repo/seeds.exs new file mode 100644 index 0000000000..ecbcea6010 --- /dev/null +++ b/server/priv/repo/seeds.exs @@ -0,0 +1,11 @@ +# Script for populating the database. You can run it as: +# +# mix run priv/repo/seeds.exs +# +# Inside the script, you can read and write to any of your +# repositories directly: +# +# Hypr.Repo.insert!(%Hypr.SomeSchema{}) +# +# We recommend using the bang functions (`insert!`, `update!` +# and so on) as they will fail if something goes wrong. diff --git a/server/priv/static/favicon.ico b/server/priv/static/favicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..7f372bfc21cdd8cb47585339d5fa4d9dd424402f GIT binary patch literal 152 zcmeAS@N?(olHy`uVBq!ia0vp^4j|0I1|(Ny7TyC=@t!V@Ar*{oFEH`~d50E!_s``s q?{G*w(7?#d#v@^nKnY_HKaYb01EZMZjMqTJ89ZJ6T-G@yGywoKK_h|y literal 0 HcmV?d00001 diff --git a/server/priv/static/images/logo.svg b/server/priv/static/images/logo.svg new file mode 100644 index 0000000000..9f26babac2 --- /dev/null +++ b/server/priv/static/images/logo.svg @@ -0,0 +1,6 @@ + diff --git a/server/priv/static/robots.txt b/server/priv/static/robots.txt new file mode 100644 index 0000000000..26e06b5f19 --- /dev/null +++ b/server/priv/static/robots.txt @@ -0,0 +1,5 @@ +# See https://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file +# +# To ban all spiders from the entire site uncomment the next two lines: +# User-agent: * +# Disallow: / diff --git a/server/test/hypr_web/controllers/error_html_test.exs b/server/test/hypr_web/controllers/error_html_test.exs new file mode 100644 index 0000000000..dd700e8cb2 --- /dev/null +++ b/server/test/hypr_web/controllers/error_html_test.exs @@ -0,0 +1,14 @@ +defmodule HyprWeb.ErrorHTMLTest do + use HyprWeb.ConnCase, async: true + + # Bring render_to_string/4 for testing custom views + import Phoenix.Template + + test "renders 404.html" do + assert render_to_string(HyprWeb.ErrorHTML, "404", "html", []) == "Not Found" + end + + test "renders 500.html" do + assert render_to_string(HyprWeb.ErrorHTML, "500", "html", []) == "Internal Server Error" + end +end diff --git a/server/test/hypr_web/controllers/error_json_test.exs b/server/test/hypr_web/controllers/error_json_test.exs new file mode 100644 index 0000000000..1c10632f2f --- /dev/null +++ b/server/test/hypr_web/controllers/error_json_test.exs @@ -0,0 +1,12 @@ +defmodule HyprWeb.ErrorJSONTest do + use HyprWeb.ConnCase, async: true + + test "renders 404" do + assert HyprWeb.ErrorJSON.render("404.json", %{}) == %{errors: %{detail: "Not Found"}} + end + + test "renders 500" do + assert HyprWeb.ErrorJSON.render("500.json", %{}) == + %{errors: %{detail: "Internal Server Error"}} + end +end diff --git a/server/test/hypr_web/controllers/page_controller_test.exs b/server/test/hypr_web/controllers/page_controller_test.exs new file mode 100644 index 0000000000..27d00f3102 --- /dev/null +++ b/server/test/hypr_web/controllers/page_controller_test.exs @@ -0,0 +1,8 @@ +defmodule HyprWeb.PageControllerTest do + use HyprWeb.ConnCase + + test "GET /", %{conn: conn} do + conn = get(conn, ~p"/") + assert html_response(conn, 200) =~ "Peace of mind from prototype to production" + end +end diff --git a/server/test/support/conn_case.ex b/server/test/support/conn_case.ex new file mode 100644 index 0000000000..b183f3f257 --- /dev/null +++ b/server/test/support/conn_case.ex @@ -0,0 +1,38 @@ +defmodule HyprWeb.ConnCase do + @moduledoc """ + This module defines the test case to be used by + tests that require setting up a connection. + + Such tests rely on `Phoenix.ConnTest` and also + import other functionality to make it easier + to build common data structures and query the data layer. + + Finally, if the test case interacts with the database, + we enable the SQL sandbox, so changes done to the database + are reverted at the end of every test. If you are using + PostgreSQL, you can even run database tests asynchronously + by setting `use HyprWeb.ConnCase, async: true`, although + this option is not recommended for other databases. + """ + + use ExUnit.CaseTemplate + + using do + quote do + # The default endpoint for testing + @endpoint HyprWeb.Endpoint + + use HyprWeb, :verified_routes + + # Import conveniences for testing with connections + import Plug.Conn + import Phoenix.ConnTest + import HyprWeb.ConnCase + end + end + + setup tags do + Hypr.DataCase.setup_sandbox(tags) + {:ok, conn: Phoenix.ConnTest.build_conn()} + end +end diff --git a/server/test/support/data_case.ex b/server/test/support/data_case.ex new file mode 100644 index 0000000000..ae43222f32 --- /dev/null +++ b/server/test/support/data_case.ex @@ -0,0 +1,58 @@ +defmodule Hypr.DataCase do + @moduledoc """ + This module defines the setup for tests requiring + access to the application's data layer. + + You may define functions here to be used as helpers in + your tests. + + Finally, if the test case interacts with the database, + we enable the SQL sandbox, so changes done to the database + are reverted at the end of every test. If you are using + PostgreSQL, you can even run database tests asynchronously + by setting `use Hypr.DataCase, async: true`, although + this option is not recommended for other databases. + """ + + use ExUnit.CaseTemplate + + using do + quote do + alias Hypr.Repo + + import Ecto + import Ecto.Changeset + import Ecto.Query + import Hypr.DataCase + end + end + + setup tags do + Hypr.DataCase.setup_sandbox(tags) + :ok + end + + @doc """ + Sets up the sandbox based on the test tags. + """ + def setup_sandbox(tags) do + pid = Ecto.Adapters.SQL.Sandbox.start_owner!(Hypr.Repo, shared: not tags[:async]) + on_exit(fn -> Ecto.Adapters.SQL.Sandbox.stop_owner(pid) end) + end + + @doc """ + A helper that transforms changeset errors into a map of messages. + + assert {:error, changeset} = Accounts.create_user(%{password: "short"}) + assert "password is too short" in errors_on(changeset).password + assert %{password: ["password is too short"]} = errors_on(changeset) + + """ + def errors_on(changeset) do + Ecto.Changeset.traverse_errors(changeset, fn {message, opts} -> + Regex.replace(~r"%{(\w+)}", message, fn _, key -> + opts |> Keyword.get(String.to_existing_atom(key), key) |> to_string() + end) + end) + end +end diff --git a/server/test/test_helper.exs b/server/test/test_helper.exs new file mode 100644 index 0000000000..7b0e22f0fe --- /dev/null +++ b/server/test/test_helper.exs @@ -0,0 +1,2 @@ +ExUnit.start() +Ecto.Adapters.SQL.Sandbox.mode(Hypr.Repo, :manual) From 12c3bf0adcd17f77afe25357afda102f83fd917f Mon Sep 17 00:00:00 2001 From: yujonglee Date: Thu, 19 Dec 2024 14:32:11 +0900 Subject: [PATCH 03/13] got it working, kind of --- server/.tool-versions | 2 + server/Taskfile.yaml | 12 + server/config/runtime.exs | 4 + server/debug.sh | 5 + server/docker-compose.yaml | 10 + .../hypr_web/components/core_components.ex | 60 ++--- .../hypr_web/components/layouts/app.html.heex | 4 +- .../components/layouts/root.html.heex | 4 +- .../hypr_web/controllers/auth_controller.ex | 28 +++ .../controllers/page_html/home.html.heex | 222 +----------------- server/lib/hypr_web/endpoint.ex | 2 + server/lib/hypr_web/plugs/auth_plug.ex | 26 ++ server/lib/hypr_web/plugs/health_plug.ex | 25 ++ server/lib/hypr_web/router.ex | 24 +- server/mix.exs | 5 +- server/mix.lock | 2 + 16 files changed, 172 insertions(+), 263 deletions(-) create mode 100644 server/.tool-versions create mode 100644 server/Taskfile.yaml create mode 100644 server/debug.sh create mode 100644 server/docker-compose.yaml create mode 100644 server/lib/hypr_web/controllers/auth_controller.ex create mode 100644 server/lib/hypr_web/plugs/auth_plug.ex create mode 100644 server/lib/hypr_web/plugs/health_plug.ex diff --git a/server/.tool-versions b/server/.tool-versions new file mode 100644 index 0000000000..ce0360e0e4 --- /dev/null +++ b/server/.tool-versions @@ -0,0 +1,2 @@ +erlang 27.0.1 +elixir 1.17.2-otp-27 diff --git a/server/Taskfile.yaml b/server/Taskfile.yaml new file mode 100644 index 0000000000..305782dbc0 --- /dev/null +++ b/server/Taskfile.yaml @@ -0,0 +1,12 @@ +version: "3" +dotenv: + - .env +tasks: + fmt: mix format + dev: + cmds: + - docker-compose up -d + - sleep 2 + - mix ecto.migrate + - iex --sname hypr --cookie hypr -S mix phx.server + - docker-compose down diff --git a/server/config/runtime.exs b/server/config/runtime.exs index 80e911fd28..72efbff52d 100644 --- a/server/config/runtime.exs +++ b/server/config/runtime.exs @@ -115,3 +115,7 @@ if config_env() == :prod do # # See https://hexdocs.pm/swoosh/Swoosh.html#module-installation for details. end + +config :stytch, + project_id: "project-test-045f680c-d466-4a1c-92d8-14dca2d061e3", + secret: "secret-test-LMar2VbT0spmQYivIG3Y5sgugiO3J79YcZI=" diff --git a/server/debug.sh b/server/debug.sh new file mode 100644 index 0000000000..a1d039af5c --- /dev/null +++ b/server/debug.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +set -e + +fly ssh console --pty --select -C "/app/bin/hypr remote" diff --git a/server/docker-compose.yaml b/server/docker-compose.yaml new file mode 100644 index 0000000000..69efdbf7e4 --- /dev/null +++ b/server/docker-compose.yaml @@ -0,0 +1,10 @@ +name: hypr +services: + db: + image: postgres:16 + environment: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_DB: hypr_dev + ports: + - 5432:5432 diff --git a/server/lib/hypr_web/components/core_components.ex b/server/lib/hypr_web/components/core_components.ex index 4161569e7d..96dae663a0 100644 --- a/server/lib/hypr_web/components/core_components.ex +++ b/server/lib/hypr_web/components/core_components.ex @@ -79,7 +79,7 @@ defmodule HyprWeb.CoreComponents do
- <%= render_slot(@inner_block) %> + {render_slot(@inner_block)}
@@ -124,9 +124,9 @@ defmodule HyprWeb.CoreComponents do

<.icon :if={@kind == :info} name="hero-information-circle-mini" class="h-4 w-4" /> <.icon :if={@kind == :error} name="hero-exclamation-circle-mini" class="h-4 w-4" /> - <%= @title %> + {@title}

-

<%= msg %>

+

{msg}

@@ -157,7 +157,7 @@ defmodule HyprWeb.CoreComponents do phx-connected={hide("#client-error")} hidden > - <%= gettext("Attempting to reconnect") %> + {gettext("Attempting to reconnect")} <.icon name="hero-arrow-path" class="ml-1 h-3 w-3 animate-spin" /> @@ -169,7 +169,7 @@ defmodule HyprWeb.CoreComponents do phx-connected={hide("#server-error")} hidden > - <%= gettext("Hang in there while we get back on track") %> + {gettext("Hang in there while we get back on track")} <.icon name="hero-arrow-path" class="ml-1 h-3 w-3 animate-spin" /> @@ -203,9 +203,9 @@ defmodule HyprWeb.CoreComponents do ~H""" <.form :let={f} for={@for} as={@as} {@rest}>
- <%= render_slot(@inner_block, f) %> + {render_slot(@inner_block, f)}
- <%= render_slot(action, f) %> + {render_slot(action, f)}
@@ -237,7 +237,7 @@ defmodule HyprWeb.CoreComponents do ]} {@rest} > - <%= render_slot(@inner_block) %> + {render_slot(@inner_block)} """ end @@ -321,9 +321,9 @@ defmodule HyprWeb.CoreComponents do class="rounded border-zinc-300 text-zinc-900 focus:ring-0" {@rest} /> - <%= @label %> + {@label} - <.error :for={msg <- @errors}><%= msg %> + <.error :for={msg <- @errors}>{msg} """ end @@ -331,7 +331,7 @@ defmodule HyprWeb.CoreComponents do def input(%{type: "select"} = assigns) do ~H"""
- <.label for={@id}><%= @label %> + <.label for={@id}>{@label} - <.error :for={msg <- @errors}><%= msg %> + <.error :for={msg <- @errors}>{msg}
""" end @@ -350,7 +350,7 @@ defmodule HyprWeb.CoreComponents do def input(%{type: "textarea"} = assigns) do ~H"""
- <.label for={@id}><%= @label %> + <.label for={@id}>{@label} - <.error :for={msg <- @errors}><%= msg %> + <.error :for={msg <- @errors}>{msg}
""" end @@ -370,7 +370,7 @@ defmodule HyprWeb.CoreComponents do def input(assigns) do ~H"""
- <.label for={@id}><%= @label %> + <.label for={@id}>{@label} - <.error :for={msg <- @errors}><%= msg %> + <.error :for={msg <- @errors}>{msg}
""" end @@ -397,7 +397,7 @@ defmodule HyprWeb.CoreComponents do def label(assigns) do ~H""" """ end @@ -411,7 +411,7 @@ defmodule HyprWeb.CoreComponents do ~H"""

<.icon name="hero-exclamation-circle-mini" class="mt-0.5 h-5 w-5 flex-none" /> - <%= render_slot(@inner_block) %> + {render_slot(@inner_block)}

""" end @@ -430,13 +430,13 @@ defmodule HyprWeb.CoreComponents do

- <%= render_slot(@inner_block) %> + {render_slot(@inner_block)}

- <%= render_slot(@subtitle) %> + {render_slot(@subtitle)}

-
<%= render_slot(@actions) %>
+
{render_slot(@actions)}
""" end @@ -477,9 +477,9 @@ defmodule HyprWeb.CoreComponents do - + @@ -497,7 +497,7 @@ defmodule HyprWeb.CoreComponents do
- <%= render_slot(col, @row_item.(row)) %> + {render_slot(col, @row_item.(row))}
@@ -508,7 +508,7 @@ defmodule HyprWeb.CoreComponents do :for={action <- @action} class="relative ml-4 font-semibold leading-6 text-zinc-900 hover:text-zinc-700" > - <%= render_slot(action, @row_item.(row)) %> + {render_slot(action, @row_item.(row))} @@ -538,8 +538,8 @@ defmodule HyprWeb.CoreComponents do
-
<%= item.title %>
-
<%= render_slot(item) %>
+
{item.title}
+
{render_slot(item)}
@@ -564,7 +564,7 @@ defmodule HyprWeb.CoreComponents do class="text-sm font-semibold leading-6 text-zinc-900 hover:text-zinc-700" > <.icon name="hero-arrow-left-solid" class="h-3 w-3" /> - <%= render_slot(@inner_block) %> + {render_slot(@inner_block)} """ diff --git a/server/lib/hypr_web/components/layouts/app.html.heex b/server/lib/hypr_web/components/layouts/app.html.heex index e23bfc81c4..3b3b607454 100644 --- a/server/lib/hypr_web/components/layouts/app.html.heex +++ b/server/lib/hypr_web/components/layouts/app.html.heex @@ -5,7 +5,7 @@

- v<%= Application.spec(:phoenix, :vsn) %> + v{Application.spec(:phoenix, :vsn)}

@@ -27,6 +27,6 @@
<.flash_group flash={@flash} /> - <%= @inner_content %> + {@inner_content}
diff --git a/server/lib/hypr_web/components/layouts/root.html.heex b/server/lib/hypr_web/components/layouts/root.html.heex index d4c396f8f1..c149fdf993 100644 --- a/server/lib/hypr_web/components/layouts/root.html.heex +++ b/server/lib/hypr_web/components/layouts/root.html.heex @@ -5,13 +5,13 @@ <.live_title suffix=" · Phoenix Framework"> - <%= assigns[:page_title] || "Hypr" %> + {assigns[:page_title] || "Hypr"} - <%= @inner_content %> + {@inner_content} diff --git a/server/lib/hypr_web/controllers/auth_controller.ex b/server/lib/hypr_web/controllers/auth_controller.ex new file mode 100644 index 0000000000..dd5a6aff84 --- /dev/null +++ b/server/lib/hypr_web/controllers/auth_controller.ex @@ -0,0 +1,28 @@ +defmodule HyprWeb.AuthController do + use HyprWeb, :controller + + def login_google(conn, _params) do + url = + Stytch.start_oauth_url( + "google", + "public-token-test-55c89e10-a4c2-4cb7-8bf2-fa1c667e49cd" + ) + + redirect(conn, external: url) + end + + def logout(conn, _params) do + conn + |> delete_session(:stytch_session_token) + |> redirect(to: "/") + end + + def callback(conn, %{"stytch_token_type" => "oauth", "token" => token}) do + {:ok, %{session: %{stytch_session: %{session_token: session_token}}, user: _user}} = + Stytch.authenticate_oauth(token, %{session_duration_minutes: 60}) + + conn + |> put_session(:stytch_session_token, session_token) + |> redirect(to: "/") + end +end diff --git a/server/lib/hypr_web/controllers/page_html/home.html.heex b/server/lib/hypr_web/controllers/page_html/home.html.heex index dc1820b11e..b590643594 100644 --- a/server/lib/hypr_web/controllers/page_html/home.html.heex +++ b/server/lib/hypr_web/controllers/page_html/home.html.heex @@ -1,222 +1,2 @@ <.flash_group flash={@flash} /> - -
-
- -

- Phoenix Framework - - v<%= Application.spec(:phoenix, :vsn) %> - -

-

- Peace of mind from prototype to production. -

-

- Build rich, interactive web applications quickly, with less code and fewer moving parts. Join our growing community of developers using Phoenix to craft APIs, HTML5 apps and more, for fun or at scale. -

- -
-
+

Home

diff --git a/server/lib/hypr_web/endpoint.ex b/server/lib/hypr_web/endpoint.ex index a655c457d2..1f5eb8cbf4 100644 --- a/server/lib/hypr_web/endpoint.ex +++ b/server/lib/hypr_web/endpoint.ex @@ -11,6 +11,8 @@ defmodule HyprWeb.Endpoint do same_site: "Lax" ] + plug HyprWeb.HealthPlug + socket "/live", Phoenix.LiveView.Socket, websocket: [connect_info: [session: @session_options]], longpoll: [connect_info: [session: @session_options]] diff --git a/server/lib/hypr_web/plugs/auth_plug.ex b/server/lib/hypr_web/plugs/auth_plug.ex new file mode 100644 index 0000000000..8a4208f821 --- /dev/null +++ b/server/lib/hypr_web/plugs/auth_plug.ex @@ -0,0 +1,26 @@ +defmodule HyprWeb.AuthPlug do + import Plug.Conn + import Phoenix.Controller, only: [redirect: 2] + + def init(opts), do: opts + + def call(conn, _opts) do + token = get_session(conn, :stytch_session_token) + + if token == nil do + redirect_to_login(conn) + else + case Stytch.authenticate_session(token, %{}) do + {:ok, %{session: _session}} -> conn + {:error, _} -> redirect_to_login(conn) + end + end + end + + defp redirect_to_login(conn) do + conn + |> delete_session(:stytch_session_token) + |> redirect(to: "/auth/google/login") + |> halt() + end +end diff --git a/server/lib/hypr_web/plugs/health_plug.ex b/server/lib/hypr_web/plugs/health_plug.ex new file mode 100644 index 0000000000..aea055307f --- /dev/null +++ b/server/lib/hypr_web/plugs/health_plug.ex @@ -0,0 +1,25 @@ +defmodule HyprWeb.HealthPlug do + import Plug.Conn + + def init(opts), do: opts + + def call(%Plug.Conn{request_path: "/health"} = conn, _opts) do + [db?()] + |> Enum.all?() + |> case do + true -> conn |> send_resp(200, "OK") |> halt() + false -> conn |> send_resp(500, "") |> halt() + end + end + + def call(conn, _opts), do: conn + + defp db?() do + try do + Ecto.Adapters.SQL.query(Hypr.Repo, "select 1", []) + :ok + rescue + DBConnection.ConnectionError -> :error + end + end +end diff --git a/server/lib/hypr_web/router.ex b/server/lib/hypr_web/router.ex index d8925492a6..8d08abe46d 100644 --- a/server/lib/hypr_web/router.ex +++ b/server/lib/hypr_web/router.ex @@ -10,24 +10,34 @@ defmodule HyprWeb.Router do plug :put_secure_browser_headers end + pipeline :browser_unauthenticated do + plug :browser + end + + pipeline :browser_authenticated do + plug :browser + plug HyprWeb.AuthPlug + end + pipeline :api do plug :accepts, ["json"] end scope "/", HyprWeb do - pipe_through :browser + pipe_through :browser_authenticated get "/", PageController, :home end - # Other scopes may use custom stacks. - # scope "/api", HyprWeb do - # pipe_through :api - # end + scope "/", HyprWeb do + pipe_through :browser_unauthenticated - # Enable Swoosh mailbox preview in development - if Application.compile_env(:hypr, :dev_routes) do + get "/auth/google/login", AuthController, :login_google + get "/auth/logout", AuthController, :logout + get "/auth/callback", AuthController, :callback + end + if Application.compile_env(:hypr, :dev_routes) do scope "/dev" do pipe_through :browser diff --git a/server/mix.exs b/server/mix.exs index 5ebac6010e..5ffea7c938 100644 --- a/server/mix.exs +++ b/server/mix.exs @@ -57,7 +57,10 @@ defmodule Hypr.MixProject do {:gettext, "~> 0.20"}, {:jason, "~> 1.2"}, {:dns_cluster, "~> 0.1.1"}, - {:bandit, "~> 1.5"} + {:bandit, "~> 1.5"}, + # + {:stytch, "~> 0.4.4"}, + {:req, "~> 0.5.8"} ] end diff --git a/server/mix.lock b/server/mix.lock index b984fed552..9a6d10cd29 100644 --- a/server/mix.lock +++ b/server/mix.lock @@ -29,6 +29,8 @@ "plug": {:hex, :plug, "1.16.1", "40c74619c12f82736d2214557dedec2e9762029b2438d6d175c5074c933edc9d", [:mix], [{:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.1.1 or ~> 1.2 or ~> 2.0", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.3 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "a13ff6b9006b03d7e33874945b2755253841b238c34071ed85b0e86057f8cddc"}, "plug_crypto": {:hex, :plug_crypto, "2.1.0", "f44309c2b06d249c27c8d3f65cfe08158ade08418cf540fd4f72d4d6863abb7b", [:mix], [], "hexpm", "131216a4b030b8f8ce0f26038bc4421ae60e4bb95c5cf5395e1421437824c4fa"}, "postgrex": {:hex, :postgrex, "0.19.3", "a0bda6e3bc75ec07fca5b0a89bffd242ca209a4822a9533e7d3e84ee80707e19", [:mix], [{:db_connection, "~> 2.1", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.5 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:table, "~> 0.1.0", [hex: :table, repo: "hexpm", optional: true]}], "hexpm", "d31c28053655b78f47f948c85bb1cf86a9c1f8ead346ba1aa0d0df017fa05b61"}, + "req": {:hex, :req, "0.5.8", "50d8d65279d6e343a5e46980ac2a70e97136182950833a1968b371e753f6a662", [:mix], [{:brotli, "~> 0.3.1", [hex: :brotli, repo: "hexpm", optional: true]}, {:ezstd, "~> 1.0", [hex: :ezstd, repo: "hexpm", optional: true]}, {:finch, "~> 0.17", [hex: :finch, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}, {:mime, "~> 2.0.6 or ~> 2.1", [hex: :mime, repo: "hexpm", optional: false]}, {:nimble_csv, "~> 1.0", [hex: :nimble_csv, repo: "hexpm", optional: true]}, {:plug, "~> 1.0", [hex: :plug, repo: "hexpm", optional: true]}], "hexpm", "d7fc5898a566477e174f26887821a3c5082b243885520ee4b45555f5d53f40ef"}, + "stytch": {:hex, :stytch, "0.4.4", "0685dc5e506e205fbe5e5ab1f03823885e53ca93c3874a046dfa45da6a5ed148", [:mix], [{:req, "~> 0.5", [hex: :req, repo: "hexpm", optional: false]}], "hexpm", "ba05010035d33ae5e867346bfa37b64944d0a1f6b75531e57020df3bf5642639"}, "swoosh": {:hex, :swoosh, "1.17.5", "14910d267a2633d4335917b37846e376e2067815601592629366c39845dad145", [:mix], [{:bandit, ">= 1.0.0", [hex: :bandit, repo: "hexpm", optional: true]}, {:cowboy, "~> 1.1 or ~> 2.4", [hex: :cowboy, repo: "hexpm", optional: true]}, {:ex_aws, "~> 2.1", [hex: :ex_aws, repo: "hexpm", optional: true]}, {:finch, "~> 0.6", [hex: :finch, repo: "hexpm", optional: true]}, {:gen_smtp, "~> 0.13 or ~> 1.0", [hex: :gen_smtp, repo: "hexpm", optional: true]}, {:hackney, "~> 1.9", [hex: :hackney, repo: "hexpm", optional: true]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}, {:mail, "~> 0.2", [hex: :mail, repo: "hexpm", optional: true]}, {:mime, "~> 1.1 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:mua, "~> 0.2.3", [hex: :mua, repo: "hexpm", optional: true]}, {:multipart, "~> 0.4", [hex: :multipart, repo: "hexpm", optional: true]}, {:plug, "~> 1.9", [hex: :plug, repo: "hexpm", optional: true]}, {:plug_cowboy, ">= 1.0.0", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:req, "~> 0.5 or ~> 1.0", [hex: :req, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.2 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "629113d477bc82c4c3bffd15a25e8becc1c7ccc0f0e67743b017caddebb06f04"}, "tailwind": {:hex, :tailwind, "0.2.4", "5706ec47182d4e7045901302bf3a333e80f3d1af65c442ba9a9eed152fb26c2e", [:mix], [{:castore, ">= 0.0.0", [hex: :castore, repo: "hexpm", optional: false]}], "hexpm", "c6e4a82b8727bab593700c998a4d98cf3d8025678bfde059aed71d0000c3e463"}, "telemetry": {:hex, :telemetry, "1.3.0", "fedebbae410d715cf8e7062c96a1ef32ec22e764197f70cda73d82778d61e7a2", [:rebar3], [], "hexpm", "7015fc8919dbe63764f4b4b87a95b7c0996bd539e0d499be6ec9d7f3875b79e6"}, From 02e7086b4ec3d84bf5df1ff1cd21af498d56b876 Mon Sep 17 00:00:00 2001 From: yujonglee Date: Thu, 19 Dec 2024 15:21:42 +0900 Subject: [PATCH 04/13] redirect got it working --- server/config/runtime.exs | 1 + .../hypr_web/controllers/auth_controller.ex | 28 +++++++++++---- server/lib/hypr_web/plugs/auth_plug.ex | 4 ++- server/lib/hypr_web/router.ex | 9 ++--- server/mix.exs | 17 +++++++-- server/mix.lock | 36 +++++++++++++++++++ 6 files changed, 81 insertions(+), 14 deletions(-) diff --git a/server/config/runtime.exs b/server/config/runtime.exs index 72efbff52d..e880241348 100644 --- a/server/config/runtime.exs +++ b/server/config/runtime.exs @@ -117,5 +117,6 @@ if config_env() == :prod do end config :stytch, + public_token: "public-token-test-55c89e10-a4c2-4cb7-8bf2-fa1c667e49cd", project_id: "project-test-045f680c-d466-4a1c-92d8-14dca2d061e3", secret: "secret-test-LMar2VbT0spmQYivIG3Y5sgugiO3J79YcZI=" diff --git a/server/lib/hypr_web/controllers/auth_controller.ex b/server/lib/hypr_web/controllers/auth_controller.ex index dd5a6aff84..e623d80d71 100644 --- a/server/lib/hypr_web/controllers/auth_controller.ex +++ b/server/lib/hypr_web/controllers/auth_controller.ex @@ -1,28 +1,44 @@ defmodule HyprWeb.AuthController do use HyprWeb, :controller - def login_google(conn, _params) do + def desktop_login_google(conn, %{"id" => id}) do + conn + |> redirect(external: ~p"/auth/web/login/google?id=#{id}") + end + + def web_login_google(conn, params) do + # https://stytch.com/docs/workspace-management/redirect-urls#user-app-state-example + redirect_url = + case params["id"] do + nil -> HyprWeb.Endpoint.url() <> ~p"/auth/web/callback" + id -> HyprWeb.Endpoint.url() <> ~p"/auth/web/callback?id=#{id}" + end + + # https://stytch.com/docs/api/oauth-google-start url = Stytch.start_oauth_url( "google", - "public-token-test-55c89e10-a4c2-4cb7-8bf2-fa1c667e49cd" + Application.fetch_env!(:stytch, :public_token), + # custom_scopes: "email profile https://www.googleapis.com/auth/calendar", + login_redirect_url: redirect_url, + signup_redirect_url: redirect_url ) redirect(conn, external: url) end - def logout(conn, _params) do + def web_logout(conn, _params) do conn |> delete_session(:stytch_session_token) - |> redirect(to: "/") + |> redirect(to: ~p"/") end - def callback(conn, %{"stytch_token_type" => "oauth", "token" => token}) do + def web_callback(conn, %{"stytch_token_type" => "oauth", "token" => token}) do {:ok, %{session: %{stytch_session: %{session_token: session_token}}, user: _user}} = Stytch.authenticate_oauth(token, %{session_duration_minutes: 60}) conn |> put_session(:stytch_session_token, session_token) - |> redirect(to: "/") + |> redirect(to: ~p"/") end end diff --git a/server/lib/hypr_web/plugs/auth_plug.ex b/server/lib/hypr_web/plugs/auth_plug.ex index 8a4208f821..eb76086b53 100644 --- a/server/lib/hypr_web/plugs/auth_plug.ex +++ b/server/lib/hypr_web/plugs/auth_plug.ex @@ -2,6 +2,8 @@ defmodule HyprWeb.AuthPlug do import Plug.Conn import Phoenix.Controller, only: [redirect: 2] + use Phoenix.VerifiedRoutes, endpoint: HyprWeb.Endpoint, router: HyprWeb.Router + def init(opts), do: opts def call(conn, _opts) do @@ -20,7 +22,7 @@ defmodule HyprWeb.AuthPlug do defp redirect_to_login(conn) do conn |> delete_session(:stytch_session_token) - |> redirect(to: "/auth/google/login") + |> redirect(to: ~p"/auth/web/login/google") |> halt() end end diff --git a/server/lib/hypr_web/router.ex b/server/lib/hypr_web/router.ex index 8d08abe46d..7e09275023 100644 --- a/server/lib/hypr_web/router.ex +++ b/server/lib/hypr_web/router.ex @@ -29,12 +29,13 @@ defmodule HyprWeb.Router do get "/", PageController, :home end - scope "/", HyprWeb do + scope "/auth", HyprWeb do pipe_through :browser_unauthenticated - get "/auth/google/login", AuthController, :login_google - get "/auth/logout", AuthController, :logout - get "/auth/callback", AuthController, :callback + get "/desktop/login/google", AuthController, :desktop_login_google + get "/web/login/google", AuthController, :web_login_google + get "/web/logout", AuthController, :web_logout + get "/web/callback", AuthController, :web_callback end if Application.compile_env(:hypr, :dev_routes) do diff --git a/server/mix.exs b/server/mix.exs index 5ffea7c938..4bf1bd22b4 100644 --- a/server/mix.exs +++ b/server/mix.exs @@ -38,8 +38,7 @@ defmodule Hypr.MixProject do {:postgrex, ">= 0.0.0"}, {:phoenix_html, "~> 4.1"}, {:phoenix_live_reload, "~> 1.2", only: :dev}, - # TODO bump on release to {:phoenix_live_view, "~> 1.0.0"}, - {:phoenix_live_view, "~> 1.0.0-rc.1", override: true}, + {:phoenix_live_view, "~> 1.0.0"}, {:floki, ">= 0.30.0", only: :test}, {:esbuild, "~> 0.8", runtime: Mix.env() == :dev}, {:tailwind, "~> 0.2", runtime: Mix.env() == :dev}, @@ -59,8 +58,20 @@ defmodule Hypr.MixProject do {:dns_cluster, "~> 0.1.1"}, {:bandit, "~> 1.5"}, # + {:ash, "~> 3.4"}, + {:ash_postgres, "~> 2.4"}, + # {:stytch, "~> 0.4.4"}, - {:req, "~> 0.5.8"} + {:req, "~> 0.5.0"}, + {:retry, "~> 0.18"}, + {:sentry, "~> 10.8"}, + {:hackney, "~> 1.8"}, + {:ex2ms, "~> 1.7"}, + {:recon, "~> 2.5", override: true}, + {:recon_ex, github: "tatsuya6502/recon_ex", ref: "0ce4c5d"}, + {:protobuf, "~> 0.13.0"}, + {:stripity_stripe, "~> 3.2"}, + {:websockex, "~> 0.4.3"} ] end diff --git a/server/mix.lock b/server/mix.lock index 9a6d10cd29..0f552885c3 100644 --- a/server/mix.lock +++ b/server/mix.lock @@ -1,24 +1,42 @@ %{ + "ash": {:hex, :ash, "3.4.47", "3d5326b45fc264419347a387b0c9ccf9e032b4d1466aa7b62c737a94585fd232", [:mix], [{:decimal, "~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:ecto, "~> 3.7", [hex: :ecto, repo: "hexpm", optional: false]}, {:ets, "~> 0.8", [hex: :ets, repo: "hexpm", optional: false]}, {:igniter, ">= 0.4.8 and < 1.0.0-0", [hex: :igniter, repo: "hexpm", optional: false]}, {:jason, ">= 1.0.0", [hex: :jason, repo: "hexpm", optional: false]}, {:owl, "~> 0.11", [hex: :owl, repo: "hexpm", optional: false]}, {:picosat_elixir, "~> 0.2", [hex: :picosat_elixir, repo: "hexpm", optional: true]}, {:plug, ">= 0.0.0", [hex: :plug, repo: "hexpm", optional: true]}, {:reactor, "~> 0.9", [hex: :reactor, repo: "hexpm", optional: false]}, {:simple_sat, ">= 0.1.1 and < 1.0.0-0", [hex: :simple_sat, repo: "hexpm", optional: true]}, {:spark, ">= 2.2.29 and < 3.0.0-0", [hex: :spark, repo: "hexpm", optional: false]}, {:splode, ">= 0.2.6 and < 1.0.0-0", [hex: :splode, repo: "hexpm", optional: false]}, {:stream_data, "~> 1.0", [hex: :stream_data, repo: "hexpm", optional: false]}, {:telemetry, "~> 1.1", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "c1e40a04efa8df5e1cbfc71b685ec846c8090a4b19a23be50450659ed259988e"}, + "ash_postgres": {:hex, :ash_postgres, "2.4.17", "cafad136259045f113715cf5bc025b085c21c423315310c71cbe2d57c78312f0", [:mix], [{:ash, ">= 3.4.44 and < 4.0.0-0", [hex: :ash, repo: "hexpm", optional: false]}, {:ash_sql, ">= 0.2.40 and < 1.0.0-0", [hex: :ash_sql, repo: "hexpm", optional: false]}, {:ecto, ">= 3.12.1 and < 4.0.0-0", [hex: :ecto, repo: "hexpm", optional: false]}, {:ecto_sql, "~> 3.12", [hex: :ecto_sql, repo: "hexpm", optional: false]}, {:igniter, ">= 0.4.4 and < 1.0.0-0", [hex: :igniter, repo: "hexpm", optional: false]}, {:inflex, "~> 2.1", [hex: :inflex, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}, {:owl, "~> 0.11", [hex: :owl, repo: "hexpm", optional: false]}, {:postgrex, ">= 0.0.0", [hex: :postgrex, repo: "hexpm", optional: false]}], "hexpm", "ef6c9b9116edb77d9343e6f36e284760c86fec7a93c6e37f1f431e84c526874f"}, + "ash_sql": {:hex, :ash_sql, "0.2.41", "9e0a1686dc67a7cdc8435ced6c998dcd4de87980dde0a72d77946bbc9d1e65cb", [:mix], [{:ash, ">= 3.1.7 and < 4.0.0-0", [hex: :ash, repo: "hexpm", optional: false]}, {:ecto, "~> 3.9", [hex: :ecto, repo: "hexpm", optional: false]}, {:ecto_sql, "~> 3.9", [hex: :ecto_sql, repo: "hexpm", optional: false]}], "hexpm", "226470dc8eeb3e89f98c0fb4ef11edf1b114e1caf3cd3457af7f9481df8221e8"}, "bandit": {:hex, :bandit, "1.6.1", "9e01b93d72ddc21d8c576a704949e86ee6cde7d11270a1d3073787876527a48f", [:mix], [{:hpax, "~> 1.0", [hex: :hpax, repo: "hexpm", optional: false]}, {:plug, "~> 1.14", [hex: :plug, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}, {:thousand_island, "~> 1.0", [hex: :thousand_island, repo: "hexpm", optional: false]}, {:websock, "~> 0.5", [hex: :websock, repo: "hexpm", optional: false]}], "hexpm", "5a904bf010ea24b67979835e0507688e31ac873d4ffc8ed0e5413e8d77455031"}, "castore": {:hex, :castore, "1.0.10", "43bbeeac820f16c89f79721af1b3e092399b3a1ecc8df1a472738fd853574911", [:mix], [], "hexpm", "1b0b7ea14d889d9ea21202c43a4fa015eb913021cb535e8ed91946f4b77a8848"}, + "certifi": {:hex, :certifi, "2.12.0", "2d1cca2ec95f59643862af91f001478c9863c2ac9cb6e2f89780bfd8de987329", [:rebar3], [], "hexpm", "ee68d85df22e554040cdb4be100f33873ac6051387baf6a8f6ce82272340ff1c"}, "db_connection": {:hex, :db_connection, "2.7.0", "b99faa9291bb09892c7da373bb82cba59aefa9b36300f6145c5f201c7adf48ec", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "dcf08f31b2701f857dfc787fbad78223d61a32204f217f15e881dd93e4bdd3ff"}, "decimal": {:hex, :decimal, "2.3.0", "3ad6255aa77b4a3c4f818171b12d237500e63525c2fd056699967a3e7ea20f62", [:mix], [], "hexpm", "a4d66355cb29cb47c3cf30e71329e58361cfcb37c34235ef3bf1d7bf3773aeac"}, "dns_cluster": {:hex, :dns_cluster, "0.1.3", "0bc20a2c88ed6cc494f2964075c359f8c2d00e1bf25518a6a6c7fd277c9b0c66", [:mix], [], "hexpm", "46cb7c4a1b3e52c7ad4cbe33ca5079fbde4840dedeafca2baf77996c2da1bc33"}, "ecto": {:hex, :ecto, "3.12.5", "4a312960ce612e17337e7cefcf9be45b95a3be6b36b6f94dfb3d8c361d631866", [:mix], [{:decimal, "~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "6eb18e80bef8bb57e17f5a7f068a1719fbda384d40fc37acb8eb8aeca493b6ea"}, "ecto_sql": {:hex, :ecto_sql, "3.12.1", "c0d0d60e85d9ff4631f12bafa454bc392ce8b9ec83531a412c12a0d415a3a4d0", [:mix], [{:db_connection, "~> 2.4.1 or ~> 2.5", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.12", [hex: :ecto, repo: "hexpm", optional: false]}, {:myxql, "~> 0.7", [hex: :myxql, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.19 or ~> 1.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:tds, "~> 2.1.1 or ~> 2.2", [hex: :tds, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.0 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "aff5b958a899762c5f09028c847569f7dfb9cc9d63bdb8133bff8a5546de6bf5"}, "esbuild": {:hex, :esbuild, "0.8.2", "5f379dfa383ef482b738e7771daf238b2d1cfb0222bef9d3b20d4c8f06c7a7ac", [:mix], [{:castore, ">= 0.0.0", [hex: :castore, repo: "hexpm", optional: false]}, {:jason, "~> 1.4", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "558a8a08ed78eb820efbfda1de196569d8bfa9b51e8371a1934fbb31345feda7"}, + "ets": {:hex, :ets, "0.9.0", "79c6a6c205436780486f72d84230c6cba2f8a9920456750ddd1e47389107d5fd", [:mix], [], "hexpm", "2861fdfb04bcaeff370f1a5904eec864f0a56dcfebe5921ea9aadf2a481c822b"}, + "ex2ms": {:hex, :ex2ms, "1.7.0", "45b9f523d0b777667ded60070d82d871a37e294f0b6c5b8eca86771f00f82ee1", [:mix], [], "hexpm", "2589eee51f81f1b1caa6d08c990b1ad409215fe6f64c73f73c67d36ed10be827"}, "expo": {:hex, :expo, "1.1.0", "f7b9ed7fb5745ebe1eeedf3d6f29226c5dd52897ac67c0f8af62a07e661e5c75", [:mix], [], "hexpm", "fbadf93f4700fb44c331362177bdca9eeb8097e8b0ef525c9cc501cb9917c960"}, "file_system": {:hex, :file_system, "1.0.1", "79e8ceaddb0416f8b8cd02a0127bdbababe7bf4a23d2a395b983c1f8b3f73edd", [:mix], [], "hexpm", "4414d1f38863ddf9120720cd976fce5bdde8e91d8283353f0e31850fa89feb9e"}, "finch": {:hex, :finch, "0.19.0", "c644641491ea854fc5c1bbaef36bfc764e3f08e7185e1f084e35e0672241b76d", [:mix], [{:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:mint, "~> 1.6.2 or ~> 1.7", [hex: :mint, repo: "hexpm", optional: false]}, {:nimble_options, "~> 0.4 or ~> 1.0", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:nimble_pool, "~> 1.1", [hex: :nimble_pool, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "fc5324ce209125d1e2fa0fcd2634601c52a787aff1cd33ee833664a5af4ea2b6"}, "floki": {:hex, :floki, "0.37.0", "b83e0280bbc6372f2a403b2848013650b16640cd2470aea6701f0632223d719e", [:mix], [], "hexpm", "516a0c15a69f78c47dc8e0b9b3724b29608aa6619379f91b1ffa47109b5d0dd3"}, "gettext": {:hex, :gettext, "0.26.2", "5978aa7b21fada6deabf1f6341ddba50bc69c999e812211903b169799208f2a8", [:mix], [{:expo, "~> 0.5.1 or ~> 1.0", [hex: :expo, repo: "hexpm", optional: false]}], "hexpm", "aa978504bcf76511efdc22d580ba08e2279caab1066b76bb9aa81c4a1e0a32a5"}, + "glob_ex": {:hex, :glob_ex, "0.1.11", "cb50d3f1ef53f6ca04d6252c7fde09fd7a1cf63387714fe96f340a1349e62c93", [:mix], [], "hexpm", "342729363056e3145e61766b416769984c329e4378f1d558b63e341020525de4"}, + "hackney": {:hex, :hackney, "1.20.1", "8d97aec62ddddd757d128bfd1df6c5861093419f8f7a4223823537bad5d064e2", [:rebar3], [{:certifi, "~> 2.12.0", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "~> 6.1.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "~> 1.0.0", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "~> 1.1", [hex: :mimerl, repo: "hexpm", optional: false]}, {:parse_trans, "3.4.1", [hex: :parse_trans, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "~> 1.1.0", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}, {:unicode_util_compat, "~> 0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "fe9094e5f1a2a2c0a7d10918fee36bfec0ec2a979994cff8cfe8058cd9af38e3"}, "heroicons": {:git, "https://github.com/tailwindlabs/heroicons.git", "88ab3a0d790e6a47404cba02800a6b25d2afae50", [tag: "v2.1.1", sparse: "optimized", depth: 1]}, "hpax": {:hex, :hpax, "1.0.1", "c857057f89e8bd71d97d9042e009df2a42705d6d690d54eca84c8b29af0787b0", [:mix], [], "hexpm", "4e2d5a4f76ae1e3048f35ae7adb1641c36265510a2d4638157fbcb53dda38445"}, + "idna": {:hex, :idna, "6.1.1", "8a63070e9f7d0c62eb9d9fcb360a7de382448200fbbd1b106cc96d3d8099df8d", [:rebar3], [{:unicode_util_compat, "~> 0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "92376eb7894412ed19ac475e4a86f7b413c1b9fbb5bd16dccd57934157944cea"}, + "igniter": {:hex, :igniter, "0.4.8", "6d1bf4934952ac3eb20f6cbac0d5cd6d8012e42e3de20ad794703556c14cfa08", [:mix], [{:glob_ex, "~> 0.1.7", [hex: :glob_ex, repo: "hexpm", optional: false]}, {:jason, "~> 1.4", [hex: :jason, repo: "hexpm", optional: false]}, {:rewrite, ">= 1.1.1 and < 2.0.0-0", [hex: :rewrite, repo: "hexpm", optional: false]}, {:sourceror, "~> 1.4", [hex: :sourceror, repo: "hexpm", optional: false]}, {:spitfire, ">= 0.1.3 and < 1.0.0-0", [hex: :spitfire, repo: "hexpm", optional: false]}], "hexpm", "f9dd06f971fa053c6b0d9f8263b625f619a0fd3645d6a8cd6170935055a8f0df"}, + "inflex": {:hex, :inflex, "2.1.0", "a365cf0821a9dacb65067abd95008ca1b0bb7dcdd85ae59965deef2aa062924c", [:mix], [], "hexpm", "14c17d05db4ee9b6d319b0bff1bdf22aa389a25398d1952c7a0b5f3d93162dd8"}, + "iterex": {:hex, :iterex, "0.1.2", "58f9b9b9a22a55cbfc7b5234a9c9c63eaac26d276b3db80936c0e1c60355a5a6", [:mix], [], "hexpm", "2e103b8bcc81757a9af121f6dc0df312c9a17220f302b1193ef720460d03029d"}, "jason": {:hex, :jason, "1.4.4", "b9226785a9aa77b6857ca22832cffa5d5011a667207eb2a0ad56adb5db443b8a", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "c5eb0cab91f094599f94d55bc63409236a8ec69a21a67814529e8d5f6cc90b3b"}, + "libgraph": {:hex, :libgraph, "0.16.0", "3936f3eca6ef826e08880230f806bfea13193e49bf153f93edcf0239d4fd1d07", [:mix], [], "hexpm", "41ca92240e8a4138c30a7e06466acc709b0cbb795c643e9e17174a178982d6bf"}, + "metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], [], "hexpm", "69b09adddc4f74a40716ae54d140f93beb0fb8978d8636eaded0c31b6f099f16"}, "mime": {:hex, :mime, "2.0.6", "8f18486773d9b15f95f4f4f1e39b710045fa1de891fada4516559967276e4dc2", [:mix], [], "hexpm", "c9945363a6b26d747389aac3643f8e0e09d30499a138ad64fe8fd1d13d9b153e"}, + "mimerl": {:hex, :mimerl, "1.3.0", "d0cd9fc04b9061f82490f6581e0128379830e78535e017f7780f37fea7545726", [:rebar3], [], "hexpm", "a1e15a50d1887217de95f0b9b0793e32853f7c258a5cd227650889b38839fe9d"}, "mint": {:hex, :mint, "1.6.2", "af6d97a4051eee4f05b5500671d47c3a67dac7386045d87a904126fd4bbcea2e", [:mix], [{:castore, "~> 0.1.0 or ~> 1.0", [hex: :castore, repo: "hexpm", optional: true]}, {:hpax, "~> 0.1.1 or ~> 0.2.0 or ~> 1.0", [hex: :hpax, repo: "hexpm", optional: false]}], "hexpm", "5ee441dffc1892f1ae59127f74afe8fd82fda6587794278d924e4d90ea3d63f9"}, "nimble_options": {:hex, :nimble_options, "1.1.1", "e3a492d54d85fc3fd7c5baf411d9d2852922f66e69476317787a7b2bb000a61b", [:mix], [], "hexpm", "821b2470ca9442c4b6984882fe9bb0389371b8ddec4d45a9504f00a66f650b44"}, + "nimble_ownership": {:hex, :nimble_ownership, "1.0.1", "f69fae0cdd451b1614364013544e66e4f5d25f36a2056a9698b793305c5aa3a6", [:mix], [], "hexpm", "3825e461025464f519f3f3e4a1f9b68c47dc151369611629ad08b636b73bb22d"}, "nimble_pool": {:hex, :nimble_pool, "1.1.0", "bf9c29fbdcba3564a8b800d1eeb5a3c58f36e1e11d7b7fb2e084a643f645f06b", [:mix], [], "hexpm", "af2e4e6b34197db81f7aad230c1118eac993acc0dae6bc83bac0126d4ae0813a"}, + "owl": {:hex, :owl, "0.12.0", "0c4b48f90797a7f5f09ebd67ba7ebdc20761c3ec9c7928dfcafcb6d3c2d25c99", [:mix], [{:ucwidth, "~> 0.2", [hex: :ucwidth, repo: "hexpm", optional: true]}], "hexpm", "241d85ae62824dd72f9b2e4a5ba4e69ebb9960089a3c68ce6c1ddf2073db3c15"}, + "parse_trans": {:hex, :parse_trans, "3.4.1", "6e6aa8167cb44cc8f39441d05193be6e6f4e7c2946cb2759f015f8c56b76e5ff", [:rebar3], [], "hexpm", "620a406ce75dada827b82e453c19cf06776be266f5a67cff34e1ef2cbb60e49a"}, "phoenix": {:hex, :phoenix, "1.7.18", "5310c21443514be44ed93c422e15870aef254cf1b3619e4f91538e7529d2b2e4", [:mix], [{:castore, ">= 0.0.0", [hex: :castore, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 2.1", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}, {:phoenix_template, "~> 1.0", [hex: :phoenix_template, repo: "hexpm", optional: false]}, {:phoenix_view, "~> 2.0", [hex: :phoenix_view, repo: "hexpm", optional: true]}, {:plug, "~> 1.14", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 2.7", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:plug_crypto, "~> 1.2 or ~> 2.0", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}, {:websock_adapter, "~> 0.5.3", [hex: :websock_adapter, repo: "hexpm", optional: false]}], "hexpm", "1797fcc82108442a66f2c77a643a62980f342bfeb63d6c9a515ab8294870004e"}, "phoenix_ecto": {:hex, :phoenix_ecto, "4.6.3", "f686701b0499a07f2e3b122d84d52ff8a31f5def386e03706c916f6feddf69ef", [:mix], [{:ecto, "~> 3.5", [hex: :ecto, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 2.14.2 or ~> 3.0 or ~> 4.1", [hex: :phoenix_html, repo: "hexpm", optional: true]}, {:plug, "~> 1.9", [hex: :plug, repo: "hexpm", optional: false]}, {:postgrex, "~> 0.16 or ~> 1.0", [hex: :postgrex, repo: "hexpm", optional: true]}], "hexpm", "909502956916a657a197f94cc1206d9a65247538de8a5e186f7537c895d95764"}, "phoenix_html": {:hex, :phoenix_html, "4.1.1", "4c064fd3873d12ebb1388425a8f2a19348cef56e7289e1998e2d2fa758aa982e", [:mix], [], "hexpm", "f2f2df5a72bc9a2f510b21497fd7d2b86d932ec0598f0210fed4114adc546c6f"}, @@ -29,14 +47,32 @@ "plug": {:hex, :plug, "1.16.1", "40c74619c12f82736d2214557dedec2e9762029b2438d6d175c5074c933edc9d", [:mix], [{:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.1.1 or ~> 1.2 or ~> 2.0", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.3 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "a13ff6b9006b03d7e33874945b2755253841b238c34071ed85b0e86057f8cddc"}, "plug_crypto": {:hex, :plug_crypto, "2.1.0", "f44309c2b06d249c27c8d3f65cfe08158ade08418cf540fd4f72d4d6863abb7b", [:mix], [], "hexpm", "131216a4b030b8f8ce0f26038bc4421ae60e4bb95c5cf5395e1421437824c4fa"}, "postgrex": {:hex, :postgrex, "0.19.3", "a0bda6e3bc75ec07fca5b0a89bffd242ca209a4822a9533e7d3e84ee80707e19", [:mix], [{:db_connection, "~> 2.1", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.5 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:table, "~> 0.1.0", [hex: :table, repo: "hexpm", optional: true]}], "hexpm", "d31c28053655b78f47f948c85bb1cf86a9c1f8ead346ba1aa0d0df017fa05b61"}, + "protobuf": {:hex, :protobuf, "0.13.0", "7a9d9aeb039f68a81717eb2efd6928fdf44f03d2c0dfdcedc7b560f5f5aae93d", [:mix], [{:jason, "~> 1.2", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm", "21092a223e3c6c144c1a291ab082a7ead32821ba77073b72c68515aa51fef570"}, + "reactor": {:hex, :reactor, "0.10.3", "41a8c34251148e36dd7c75aa8433f2c2f283f29c097f9eb84a630ab28dd75651", [:mix], [{:igniter, "~> 0.4", [hex: :igniter, repo: "hexpm", optional: true]}, {:iterex, "~> 0.1", [hex: :iterex, repo: "hexpm", optional: false]}, {:libgraph, "~> 0.16", [hex: :libgraph, repo: "hexpm", optional: false]}, {:spark, "~> 2.0", [hex: :spark, repo: "hexpm", optional: false]}, {:splode, "~> 0.2", [hex: :splode, repo: "hexpm", optional: false]}, {:telemetry, "~> 1.2", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "2b34380e22b69a35943a7bcceffd5a8b766870f1fc9052162a7ff74ef9cdb3b2"}, + "recon": {:hex, :recon, "2.5.6", "9052588e83bfedfd9b72e1034532aee2a5369d9d9343b61aeb7fbce761010741", [:mix, :rebar3], [], "hexpm", "96c6799792d735cc0f0fd0f86267e9d351e63339cbe03df9d162010cefc26bb0"}, + "recon_ex": {:git, "https://github.com/tatsuya6502/recon_ex.git", "0ce4c5da777937a5bb57d3e68b9afcb9877c1c3b", [ref: "0ce4c5d"]}, "req": {:hex, :req, "0.5.8", "50d8d65279d6e343a5e46980ac2a70e97136182950833a1968b371e753f6a662", [:mix], [{:brotli, "~> 0.3.1", [hex: :brotli, repo: "hexpm", optional: true]}, {:ezstd, "~> 1.0", [hex: :ezstd, repo: "hexpm", optional: true]}, {:finch, "~> 0.17", [hex: :finch, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}, {:mime, "~> 2.0.6 or ~> 2.1", [hex: :mime, repo: "hexpm", optional: false]}, {:nimble_csv, "~> 1.0", [hex: :nimble_csv, repo: "hexpm", optional: true]}, {:plug, "~> 1.0", [hex: :plug, repo: "hexpm", optional: true]}], "hexpm", "d7fc5898a566477e174f26887821a3c5082b243885520ee4b45555f5d53f40ef"}, + "retry": {:hex, :retry, "0.18.0", "dc58ebe22c95aa00bc2459f9e0c5400e6005541cf8539925af0aa027dc860543", [:mix], [], "hexpm", "9483959cc7bf69c9e576d9dfb2b678b71c045d3e6f39ab7c9aa1489df4492d73"}, + "rewrite": {:hex, :rewrite, "1.1.1", "0e6674eb5f8cb11aabe5ad6207151b4156bf173aa9b43133a68f8cc882364570", [:mix], [{:glob_ex, "~> 0.1", [hex: :glob_ex, repo: "hexpm", optional: false]}, {:sourceror, "~> 1.0", [hex: :sourceror, repo: "hexpm", optional: false]}, {:text_diff, "~> 0.1", [hex: :text_diff, repo: "hexpm", optional: false]}], "hexpm", "fcd688b3ca543c3a1f1f4615ccc054ec37cfcde91133a27a683ec09b35ae1496"}, + "sentry": {:hex, :sentry, "10.8.1", "aa45309785e1521416225adb16e0b4d8b957578804527f3c7babb6fefbc5e456", [:mix], [{:hackney, "~> 1.8", [hex: :hackney, repo: "hexpm", optional: true]}, {:jason, "~> 1.1", [hex: :jason, repo: "hexpm", optional: true]}, {:nimble_options, "~> 1.0", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:nimble_ownership, "~> 0.3.0 or ~> 1.0", [hex: :nimble_ownership, repo: "hexpm", optional: false]}, {:phoenix, "~> 1.6", [hex: :phoenix, repo: "hexpm", optional: true]}, {:phoenix_live_view, "~> 0.20 or ~> 1.0", [hex: :phoenix_live_view, repo: "hexpm", optional: true]}, {:plug, "~> 1.6", [hex: :plug, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: true]}], "hexpm", "495b3cdadad90ba72eef973aa3dec39b3b8b2a362fe87e2f4ef32133ac3b4097"}, + "sourceror": {:hex, :sourceror, "1.7.1", "599d78f4cc2be7d55c9c4fd0a8d772fd0478e3a50e726697c20d13d02aa056d4", [:mix], [], "hexpm", "cd6f268fe29fa00afbc535e215158680a0662b357dc784646d7dff28ac65a0fc"}, + "spark": {:hex, :spark, "2.2.36", "07c921e5efb27f184267c3431d2f82099e24cac90748a47383dd75cbfb558268", [:mix], [{:igniter, ">= 0.3.64 and < 1.0.0-0", [hex: :igniter, repo: "hexpm", optional: true]}, {:jason, "~> 1.4", [hex: :jason, repo: "hexpm", optional: false]}, {:sourceror, "~> 1.2", [hex: :sourceror, repo: "hexpm", optional: false]}], "hexpm", "e5ac56b75e5ad43da6d8302b6713277488f8e9a3abdba9aae8f0d0f9cff04538"}, + "spitfire": {:hex, :spitfire, "0.1.3", "7ea0f544005dfbe48e615ed90250c9a271bfe126914012023fd5e4b6b82b7ec7", [:mix], [], "hexpm", "d53b5107bcff526a05c5bb54c95e77b36834550affd5830c9f58760e8c543657"}, + "splode": {:hex, :splode, "0.2.7", "ed042fa9bd8fe7b66dd0a0faabdb97352058420d90cd1c7c1537f609deb7ef6d", [:mix], [], "hexpm", "267f1f51d5a5ac988cda0649498294844988c5086916fed5a8aff297d69a2059"}, + "ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.7", "354c321cf377240c7b8716899e182ce4890c5938111a1296add3ec74cf1715df", [:make, :mix, :rebar3], [], "hexpm", "fe4c190e8f37401d30167c8c405eda19469f34577987c76dde613e838bbc67f8"}, + "stream_data": {:hex, :stream_data, "1.1.2", "05499eaec0443349ff877aaabc6e194e82bda6799b9ce6aaa1aadac15a9fdb4d", [:mix], [], "hexpm", "129558d2c77cbc1eb2f4747acbbea79e181a5da51108457000020a906813a1a9"}, + "stripity_stripe": {:hex, :stripity_stripe, "3.2.0", "07c27f5f2ac87006945b5c997b99d1210e009e380ea78d339d025b11c9c745f5", [:mix], [{:hackney, "~> 1.18", [hex: :hackney, repo: "hexpm", optional: false]}, {:jason, "~> 1.1", [hex: :jason, repo: "hexpm", optional: false]}, {:plug, "~> 1.14", [hex: :plug, repo: "hexpm", optional: true]}, {:telemetry, "~> 1.1", [hex: :telemetry, repo: "hexpm", optional: false]}, {:uri_query, "~> 0.2.0", [hex: :uri_query, repo: "hexpm", optional: false]}], "hexpm", "f797936a9e9538370bae7dc73d73eafd7e44ecdc95b71c88492c43f6df094cb0"}, "stytch": {:hex, :stytch, "0.4.4", "0685dc5e506e205fbe5e5ab1f03823885e53ca93c3874a046dfa45da6a5ed148", [:mix], [{:req, "~> 0.5", [hex: :req, repo: "hexpm", optional: false]}], "hexpm", "ba05010035d33ae5e867346bfa37b64944d0a1f6b75531e57020df3bf5642639"}, "swoosh": {:hex, :swoosh, "1.17.5", "14910d267a2633d4335917b37846e376e2067815601592629366c39845dad145", [:mix], [{:bandit, ">= 1.0.0", [hex: :bandit, repo: "hexpm", optional: true]}, {:cowboy, "~> 1.1 or ~> 2.4", [hex: :cowboy, repo: "hexpm", optional: true]}, {:ex_aws, "~> 2.1", [hex: :ex_aws, repo: "hexpm", optional: true]}, {:finch, "~> 0.6", [hex: :finch, repo: "hexpm", optional: true]}, {:gen_smtp, "~> 0.13 or ~> 1.0", [hex: :gen_smtp, repo: "hexpm", optional: true]}, {:hackney, "~> 1.9", [hex: :hackney, repo: "hexpm", optional: true]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}, {:mail, "~> 0.2", [hex: :mail, repo: "hexpm", optional: true]}, {:mime, "~> 1.1 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:mua, "~> 0.2.3", [hex: :mua, repo: "hexpm", optional: true]}, {:multipart, "~> 0.4", [hex: :multipart, repo: "hexpm", optional: true]}, {:plug, "~> 1.9", [hex: :plug, repo: "hexpm", optional: true]}, {:plug_cowboy, ">= 1.0.0", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:req, "~> 0.5 or ~> 1.0", [hex: :req, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.2 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "629113d477bc82c4c3bffd15a25e8becc1c7ccc0f0e67743b017caddebb06f04"}, "tailwind": {:hex, :tailwind, "0.2.4", "5706ec47182d4e7045901302bf3a333e80f3d1af65c442ba9a9eed152fb26c2e", [:mix], [{:castore, ">= 0.0.0", [hex: :castore, repo: "hexpm", optional: false]}], "hexpm", "c6e4a82b8727bab593700c998a4d98cf3d8025678bfde059aed71d0000c3e463"}, "telemetry": {:hex, :telemetry, "1.3.0", "fedebbae410d715cf8e7062c96a1ef32ec22e764197f70cda73d82778d61e7a2", [:rebar3], [], "hexpm", "7015fc8919dbe63764f4b4b87a95b7c0996bd539e0d499be6ec9d7f3875b79e6"}, "telemetry_metrics": {:hex, :telemetry_metrics, "1.0.0", "29f5f84991ca98b8eb02fc208b2e6de7c95f8bb2294ef244a176675adc7775df", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "f23713b3847286a534e005126d4c959ebcca68ae9582118ce436b521d1d47d5d"}, "telemetry_poller": {:hex, :telemetry_poller, "1.1.0", "58fa7c216257291caaf8d05678c8d01bd45f4bdbc1286838a28c4bb62ef32999", [:rebar3], [{:telemetry, "~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "9eb9d9cbfd81cbd7cdd24682f8711b6e2b691289a0de6826e58452f28c103c8f"}, + "text_diff": {:hex, :text_diff, "0.1.0", "1caf3175e11a53a9a139bc9339bd607c47b9e376b073d4571c031913317fecaa", [:mix], [], "hexpm", "d1ffaaecab338e49357b6daa82e435f877e0649041ace7755583a0ea3362dbd7"}, "thousand_island": {:hex, :thousand_island, "1.3.7", "1da7598c0f4f5f50562c097a3f8af308ded48cd35139f0e6f17d9443e4d0c9c5", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "0139335079953de41d381a6134d8b618d53d084f558c734f2662d1a72818dd12"}, + "unicode_util_compat": {:hex, :unicode_util_compat, "0.7.0", "bc84380c9ab48177092f43ac89e4dfa2c6d62b40b8bd132b1059ecc7232f9a78", [:rebar3], [], "hexpm", "25eee6d67df61960cf6a794239566599b09e17e668d3700247bc498638152521"}, + "uri_query": {:hex, :uri_query, "0.2.0", "0f5e0f7ea6d9e6a7fb4929a81df9ecd756e3c71bdee5c9bc14e57d90069a82f7", [:mix], [], "hexpm", "e99f50a6af7c6643dff948db152a6a420bfe446aaec7f0924cfcdb710c175e63"}, "websock": {:hex, :websock, "0.5.3", "2f69a6ebe810328555b6fe5c831a851f485e303a7c8ce6c5f675abeb20ebdadc", [:mix], [], "hexpm", "6105453d7fac22c712ad66fab1d45abdf049868f253cf719b625151460b8b453"}, "websock_adapter": {:hex, :websock_adapter, "0.5.8", "3b97dc94e407e2d1fc666b2fb9acf6be81a1798a2602294aac000260a7c4a47d", [:mix], [{:bandit, ">= 0.6.0", [hex: :bandit, repo: "hexpm", optional: true]}, {:plug, "~> 1.14", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 2.6", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:websock, "~> 0.5", [hex: :websock, repo: "hexpm", optional: false]}], "hexpm", "315b9a1865552212b5f35140ad194e67ce31af45bcee443d4ecb96b5fd3f3782"}, + "websockex": {:hex, :websockex, "0.4.3", "92b7905769c79c6480c02daacaca2ddd49de936d912976a4d3c923723b647bf0", [:mix], [], "hexpm", "95f2e7072b85a3a4cc385602d42115b73ce0b74a9121d0d6dbbf557645ac53e4"}, } From eeb5d73efe8aec61e482e0f1b9291b0e3dc48986 Mon Sep 17 00:00:00 2001 From: yujonglee Date: Thu, 19 Dec 2024 15:40:17 +0900 Subject: [PATCH 05/13] fix gettext warnings --- server/lib/hypr_web/components/core_components.ex | 2 +- server/lib/hypr_web/gettext.ex | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/server/lib/hypr_web/components/core_components.ex b/server/lib/hypr_web/components/core_components.ex index 96dae663a0..7f9eb2719e 100644 --- a/server/lib/hypr_web/components/core_components.ex +++ b/server/lib/hypr_web/components/core_components.ex @@ -17,7 +17,7 @@ defmodule HyprWeb.CoreComponents do use Phoenix.Component alias Phoenix.LiveView.JS - import HyprWeb.Gettext + use Gettext, backend: HyprWeb.Gettext @doc """ Renders a modal. diff --git a/server/lib/hypr_web/gettext.ex b/server/lib/hypr_web/gettext.ex index 282d7bded8..6451ac4837 100644 --- a/server/lib/hypr_web/gettext.ex +++ b/server/lib/hypr_web/gettext.ex @@ -20,5 +20,5 @@ defmodule HyprWeb.Gettext do See the [Gettext Docs](https://hexdocs.pm/gettext) for detailed usage. """ - use Gettext, otp_app: :hypr + use Gettext.Backend, otp_app: :hypr end From be8c120f2f78a3e9f28150b2d439fb474e080c38 Mon Sep 17 00:00:00 2001 From: yujonglee Date: Thu, 19 Dec 2024 17:40:28 +0900 Subject: [PATCH 06/13] copy code from old server --- server/lib/hypr/application.ex | 30 +++-- server/lib/hypr/stripe_webhook_listener.ex | 60 +++++++++ server/lib/hypr/stt/deepgram.ex | 119 ++++++++++++++++++ server/lib/hypr/stt/stt.ex | 7 ++ server/lib/hypr_web/endpoint.ex | 4 + server/lib/hypr_web/session.ex | 78 ++++++++++++ server/lib/hypr_web/stripe_webhook_handler.ex | 28 +++++ server/lib/proto/v0.pb.ex | 15 +++ 8 files changed, 329 insertions(+), 12 deletions(-) create mode 100644 server/lib/hypr/stripe_webhook_listener.ex create mode 100644 server/lib/hypr/stt/deepgram.ex create mode 100644 server/lib/hypr/stt/stt.ex create mode 100644 server/lib/hypr_web/session.ex create mode 100644 server/lib/hypr_web/stripe_webhook_handler.ex create mode 100644 server/lib/proto/v0.pb.ex diff --git a/server/lib/hypr/application.ex b/server/lib/hypr/application.ex index 4f5401cac0..4d9fdaae4e 100644 --- a/server/lib/hypr/application.ex +++ b/server/lib/hypr/application.ex @@ -7,18 +7,15 @@ defmodule Hypr.Application do @impl true def start(_type, _args) do - children = [ - HyprWeb.Telemetry, - Hypr.Repo, - {DNSCluster, query: Application.get_env(:hypr, :dns_cluster_query) || :ignore}, - {Phoenix.PubSub, name: Hypr.PubSub}, - # Start the Finch HTTP client for sending emails - {Finch, name: Hypr.Finch}, - # Start a worker by calling: Hypr.Worker.start_link(arg) - # {Hypr.Worker, arg}, - # Start to serve requests, typically the last entry - HyprWeb.Endpoint - ] + children = + [ + HyprWeb.Telemetry, + Hypr.Repo, + {DNSCluster, query: Application.get_env(:hypr, :dns_cluster_query) || :ignore}, + {Phoenix.PubSub, name: Hypr.PubSub}, + # Start the Finch HTTP client for sending emails + {Finch, name: Hypr.Finch} + ] ++ stripe() ++ [HyprWeb.Endpoint] # See https://hexdocs.pm/elixir/Supervisor.html # for other strategies and supported options @@ -26,6 +23,15 @@ defmodule Hypr.Application do Supervisor.start_link(children, opts) end + defp stripe() do + if Application.get_env(:hypr, :dev_routes, false) and + Phoenix.Endpoint.server?(:hypr, HyprWeb.Endpoint) do + [{Hypr.StripeWebhookListener, [forward_to: "http://localhost:4000/webhook/stripe"]}] + else + [] + end + end + # Tell Phoenix to update the endpoint configuration # whenever the application is updated. @impl true diff --git a/server/lib/hypr/stripe_webhook_listener.ex b/server/lib/hypr/stripe_webhook_listener.ex new file mode 100644 index 0000000000..3faa778dca --- /dev/null +++ b/server/lib/hypr/stripe_webhook_listener.ex @@ -0,0 +1,60 @@ +defmodule Hypr.StripeWebhookListener do + use GenServer + require Logger + + def start_link(options) do + {stripe_cli, options} = Keyword.pop(options, :stripe_cli, System.find_executable("stripe")) + {forward_to, options} = Keyword.pop!(options, :forward_to) + options = Keyword.validate!(options, [:name, :timeout, :debug, :spawn_opt, :hibernate_after]) + GenServer.start_link(__MODULE__, %{stripe_cli: stripe_cli, forward_to: forward_to}, options) + end + + @impl true + def init(%{stripe_cli: nil}) do + Logger.warning("Stripe CLI not found") + :ignore + end + + def init(%{stripe_cli: stripe_cli, forward_to: forward_to}) do + # https://docs.stripe.com/cli/listen + args = [ + "listen", + "--skip-verify", + "--forward-to", + forward_to + ] + + port = + Port.open( + {:spawn_executable, stripe_cli}, + [ + :binary, + :stderr_to_stdout, + line: 2048, + args: args + ] + ) + + {:ok, port} + end + + @impl true + def handle_info({port, {:data, {:eol, line}}}, port) do + secret = extract_secret(line) + + if is_nil(secret) do + Logger.info("stripe: #{line}") + else + Application.put_env(:hypr, :stripe_webhook_secret, secret) + end + + {:noreply, port} + end + + defp extract_secret(text) do + case Regex.run(~r/webhook signing secret is (whsec_[a-f0-9]{64})/, text) do + [_, secret] -> secret + _ -> nil + end + end +end diff --git a/server/lib/hypr/stt/deepgram.ex b/server/lib/hypr/stt/deepgram.ex new file mode 100644 index 0000000000..9daf4233be --- /dev/null +++ b/server/lib/hypr/stt/deepgram.ex @@ -0,0 +1,119 @@ +# https://developers.deepgram.com/docs/lower-level-websockets + +defmodule Hypr.STT.Streaming.Deepgram do + @behaviour Hypr.STT.Streaming + + use WebSockex + + @impl Hypr.STT.Streaming + def start_link(%{handle_stt: _} = state) do + params = + %{ + # https://developers.deepgram.com/docs/model + model: "nova-2-general", + # https://developers.deepgram.com/docs/speech-started + vad_events: true, + # https://developers.deepgram.com/docs/utterance-end + utterance_end_ms: 1000, + interim_results: true, + # https://developers.deepgram.com/docs/endpointing + # https://developers.deepgram.com/docs/understand-endpointing-interim-results#controlling-endpointing + endpointing: 20, + # https://developers.deepgram.com/docs/filler-words + filler_words: true + } + |> Map.merge(%{ + # https://developers.deepgram.com/docs/encoding + encoding: "linear16", + sample_rate: 16000 + }) + + # https://developers.deepgram.com/reference/listen-live + url = + URI.new!("wss://api.deepgram.com") + |> URI.append_path("/v1/listen") + |> URI.append_query(URI.encode_query(params)) + |> URI.to_string() + + # https://developers.deepgram.com/docs/authentication + api_key = Application.fetch_env!(:hypr, :deepgram_api_key) + headers = [{"Authorization", "Token #{api_key}"}] + + state = + state + |> Map.put(:speaking?, false) + |> Map.put(:vad_queue, Queue.new(2)) + + with {:ok, pid} <- WebSockex.start_link(url, __MODULE__, state, extra_headers: headers) do + Process.send_after(pid, :keep_alive, 3000) + {:ok, pid} + end + end + + @impl Hypr.STT.Streaming + def send_audio(pid, audio, _opts \\ []) do + WebSockex.cast(pid, {:audio, audio}) + end + + @impl WebSockex + def handle_cast({:audio, audio}, state) do + # https://developers.deepgram.com/reference/listen-live#sending-audio-data + {:reply, {:binary, audio}, state} + end + + @impl WebSockex + def handle_frame({:text, data}, state), do: handle_in(Jason.decode!(data), state) + + # https://developers.deepgram.com/reference/listen-live#response-schema + # https://developers.deepgram.com/docs/understand-endpointing-interim-results + # https://developers.deepgram.com/docs/understanding-end-of-speech-detection + defp handle_in( + %{ + "type" => "Results", + "is_final" => _is_final, + "speech_final" => _speech_final, + "channel" => %{"alternatives" => [%{"transcript" => transcript} | _]} + }, + state + ) do + if not state.speaking? do + state.handle_stt.({:transcript, transcript}) + state.handle_stt.(:utterance_end) + {:ok, Map.put(state, :speaking?, false)} + else + {:ok, state} + end + end + + # https://developers.deepgram.com/docs/speech-started + defp handle_in(%{"type" => "SpeechStarted"}, state), do: {:ok, state} + + # https://developers.deepgram.com/docs/utterance-end + defp handle_in(%{"type" => "UtteranceEnd"}, state), do: {:ok, state} + + defp handle_in(_, state), do: {:ok, state} + + # https://developers.deepgram.com/docs/audio-keep-alive#sending-keepalive + @impl WebSockex + def handle_info(:keep_alive, state) do + Process.send_after(self(), :keep_alive, 3000) + + msg = Jason.encode!(%{type: "KeepAlive"}) + {:reply, {:text, msg}, state} + end + + # https://developers.deepgram.com/docs/finalize + def handle_info(:flush, state) do + msg = Jason.encode!(%{type: "Finalize"}) + {:reply, {:text, msg}, state} + end + + @impl WebSockex + def terminate(reason, state) do + IO.inspect(reason) + + # https://developers.deepgram.com/docs/close-stream + msg = Jason.encode!(%{type: "CloseStream"}) + {:reply, {:text, msg}, state} + end +end diff --git a/server/lib/hypr/stt/stt.ex b/server/lib/hypr/stt/stt.ex new file mode 100644 index 0000000000..cf44080ab0 --- /dev/null +++ b/server/lib/hypr/stt/stt.ex @@ -0,0 +1,7 @@ +defmodule Hypr.STT.Streaming do + @callback send_audio(pid(), binary(), keyword()) :: :ok | {:error, any()} + + def child_spec(arg), do: impl().child_spec(arg) + def send_audio(client, audio, opts \\ []), do: impl().send_audio(client, audio, opts) + def impl(), do: Application.get_env(:hypr, :stt_streaming, Hypr.STT.Streaming.Deepgram) +end diff --git a/server/lib/hypr_web/endpoint.ex b/server/lib/hypr_web/endpoint.ex index 1f5eb8cbf4..7e7a9c2671 100644 --- a/server/lib/hypr_web/endpoint.ex +++ b/server/lib/hypr_web/endpoint.ex @@ -13,6 +13,10 @@ defmodule HyprWeb.Endpoint do plug HyprWeb.HealthPlug + socket "/v0/session", HyprWeb.Session, + websocket: [path: "/", connect_info: [:uri, :x_headers]], + longpoll: false + socket "/live", Phoenix.LiveView.Socket, websocket: [connect_info: [session: @session_options]], longpoll: [connect_info: [session: @session_options]] diff --git a/server/lib/hypr_web/session.ex b/server/lib/hypr_web/session.ex new file mode 100644 index 0000000000..0cb5d25768 --- /dev/null +++ b/server/lib/hypr_web/session.ex @@ -0,0 +1,78 @@ +defmodule HyprWeb.Session do + @behaviour Phoenix.Socket.Transport + + @impl Phoenix.Socket.Transport + def child_spec(_opts), do: :ignore + + @impl Phoenix.Socket.Transport + def connect(transport_info) do + IO.inspect(transport_info) + {:ok, %{}} + end + + @impl Phoenix.Socket.Transport + def init(state) do + state = + state + |> Map.put(:supervisor_pid, nil) + + {:ok, state} + end + + @impl Phoenix.Socket.Transport + def handle_in({_, _opts}, state) do + state = + state + |> Map.put(:supervisor_pid, start_supervisor()) + + {:ok, state} + end + + @impl Phoenix.Socket.Transport + def handle_info({:stt, {:transcript, _text}}, state) do + {:ok, state} + end + + @impl Phoenix.Socket.Transport + def handle_info(_, state) do + {:ok, state} + end + + @impl Phoenix.Socket.Transport + def terminate(:remote, _state), do: :ok + def terminate({:error, :closed}, _state), do: :ok + def terminate({:error, :idle}, _state), do: :ok + def terminate({:error, :supervisor_died}, _state), do: :ok + + def terminate(e, _state) do + IO.inspect(e) + :ok + end + + defp start_supervisor() do + here = self() + + {:ok, pid} = + Supervisor.start_link(HyprWeb.Session.Supervisor, + strategy: :one_for_one, + handle_stt: &send(here, {:stt, &1}) + ) + + pid + end +end + +defmodule HyprWeb.Session.Supervisor do + use Supervisor + + def start_link(opts) do + Supervisor.start_link(__MODULE__, opts) + end + + def init(opts) do + {handle_stt, opts} = Keyword.pop(opts, :handle_stt, &IO.inspect/1) + + children = [{Hypr.STT.Streaming, %{handle_stt: handle_stt}}] + Supervisor.init(children, opts) + end +end diff --git a/server/lib/hypr_web/stripe_webhook_handler.ex b/server/lib/hypr_web/stripe_webhook_handler.ex new file mode 100644 index 0000000000..0d690d56be --- /dev/null +++ b/server/lib/hypr_web/stripe_webhook_handler.ex @@ -0,0 +1,28 @@ +# https://docs.stripe.com/billing/subscriptions/webhooks#events +defmodule HyprWeb.StripeWebhookHandler do + @behaviour Stripe.WebhookHandler + require Logger + + @impl true + def handle_event(%Stripe.Event{type: type, data: data}) + when type in ["customer.created", "customer.updated"] do + %{object: %Stripe.Customer{} = _customer} = data + + :ok + end + + @impl true + def handle_event(%Stripe.Event{type: type, data: data}) + when type in [ + "customer.subscription.created", + "customer.subscription.updated", + "customer.subscription.deleted" + ] do + %{object: %Stripe.Subscription{customer: _id} = _subscription} = data + + :ok + end + + @impl true + def handle_event(_event), do: :ok +end diff --git a/server/lib/proto/v0.pb.ex b/server/lib/proto/v0.pb.ex new file mode 100644 index 0000000000..ae3b3d16b5 --- /dev/null +++ b/server/lib/proto/v0.pb.ex @@ -0,0 +1,15 @@ +defmodule Hypr.V0.TranscribeInputChunk do + @moduledoc false + + use Protobuf, syntax: :proto3, protoc_gen_elixir_version: "0.13.0" + + field :audio, 1, type: :bytes +end + +defmodule Hypr.V0.TranscribeOutputChunk do + @moduledoc false + + use Protobuf, syntax: :proto3, protoc_gen_elixir_version: "0.13.0" + + field :text, 1, type: :string +end From 10430540c69a2af45b98a359a89e34a31bc63433 Mon Sep 17 00:00:00 2001 From: yujonglee Date: Thu, 19 Dec 2024 17:42:35 +0900 Subject: [PATCH 07/13] remove old server --- server-old/.dockerignore | 45 ------- server-old/.formatter.exs | 5 - server-old/.gitignore | 27 ---- server-old/.tool-versions | 2 - server-old/Dockerfile | 92 -------------- server-old/README.md | 1 - server-old/Taskfile.yaml | 12 -- server-old/config/config.exs | 35 ------ server-old/config/dev.exs | 63 ---------- server-old/config/prod.exs | 7 -- server-old/config/runtime.exs | 97 -------------- server-old/config/test.exs | 27 ---- server-old/debug.sh | 5 - server-old/docker-compose.yaml | 10 -- server-old/fly.toml | 42 ------- server-old/lib/hypr.ex | 9 -- server-old/lib/hypr/application.ex | 40 ------ server-old/lib/hypr/release.ex | 28 ----- server-old/lib/hypr/repo.ex | 5 - .../lib/hypr/stripe_webhook_listener.ex | 60 --------- server-old/lib/hypr/stt/deepgram.ex | 119 ------------------ server-old/lib/hypr/stt/stt.ex | 7 -- server-old/lib/hypr_web.ex | 65 ---------- .../lib/hypr_web/controllers/error_json.ex | 21 ---- server-old/lib/hypr_web/endpoint.ex | 53 -------- server-old/lib/hypr_web/plugs/health.ex | 25 ---- server-old/lib/hypr_web/router.ex | 11 -- server-old/lib/hypr_web/session.ex | 75 ----------- .../lib/hypr_web/stripe_webhook_handler.ex | 28 ----- server-old/lib/hypr_web/telemetry.ex | 92 -------------- server-old/lib/proto/v0.pb.ex | 15 --- server-old/mix.exs | 76 ----------- server-old/mix.lock | 70 ----------- .../priv/repo/migrations/.formatter.exs | 4 - server-old/priv/repo/seeds.exs | 11 -- server-old/priv/static/favicon.ico | Bin 152 -> 0 bytes server-old/priv/static/robots.txt | 5 - server-old/rel/env.sh.eex | 13 -- server-old/rel/overlays/bin/migrate | 5 - server-old/rel/overlays/bin/migrate.bat | 1 - server-old/rel/overlays/bin/server | 5 - server-old/rel/overlays/bin/server.bat | 2 - .../hypr_web/controllers/error_json_test.exs | 12 -- server-old/test/support/conn_case.ex | 38 ------ server-old/test/support/data_case.ex | 58 --------- server-old/test/test_helper.exs | 2 - 46 files changed, 1425 deletions(-) delete mode 100644 server-old/.dockerignore delete mode 100644 server-old/.formatter.exs delete mode 100644 server-old/.gitignore delete mode 100644 server-old/.tool-versions delete mode 100644 server-old/Dockerfile delete mode 100644 server-old/README.md delete mode 100644 server-old/Taskfile.yaml delete mode 100644 server-old/config/config.exs delete mode 100644 server-old/config/dev.exs delete mode 100644 server-old/config/prod.exs delete mode 100644 server-old/config/runtime.exs delete mode 100644 server-old/config/test.exs delete mode 100644 server-old/debug.sh delete mode 100644 server-old/docker-compose.yaml delete mode 100644 server-old/fly.toml delete mode 100644 server-old/lib/hypr.ex delete mode 100644 server-old/lib/hypr/application.ex delete mode 100644 server-old/lib/hypr/release.ex delete mode 100644 server-old/lib/hypr/repo.ex delete mode 100644 server-old/lib/hypr/stripe_webhook_listener.ex delete mode 100644 server-old/lib/hypr/stt/deepgram.ex delete mode 100644 server-old/lib/hypr/stt/stt.ex delete mode 100644 server-old/lib/hypr_web.ex delete mode 100644 server-old/lib/hypr_web/controllers/error_json.ex delete mode 100644 server-old/lib/hypr_web/endpoint.ex delete mode 100644 server-old/lib/hypr_web/plugs/health.ex delete mode 100644 server-old/lib/hypr_web/router.ex delete mode 100644 server-old/lib/hypr_web/session.ex delete mode 100644 server-old/lib/hypr_web/stripe_webhook_handler.ex delete mode 100644 server-old/lib/hypr_web/telemetry.ex delete mode 100644 server-old/lib/proto/v0.pb.ex delete mode 100644 server-old/mix.exs delete mode 100644 server-old/mix.lock delete mode 100644 server-old/priv/repo/migrations/.formatter.exs delete mode 100644 server-old/priv/repo/seeds.exs delete mode 100644 server-old/priv/static/favicon.ico delete mode 100644 server-old/priv/static/robots.txt delete mode 100755 server-old/rel/env.sh.eex delete mode 100755 server-old/rel/overlays/bin/migrate delete mode 100755 server-old/rel/overlays/bin/migrate.bat delete mode 100755 server-old/rel/overlays/bin/server delete mode 100755 server-old/rel/overlays/bin/server.bat delete mode 100644 server-old/test/hypr_web/controllers/error_json_test.exs delete mode 100644 server-old/test/support/conn_case.ex delete mode 100644 server-old/test/support/data_case.ex delete mode 100644 server-old/test/test_helper.exs diff --git a/server-old/.dockerignore b/server-old/.dockerignore deleted file mode 100644 index 61a73933c8..0000000000 --- a/server-old/.dockerignore +++ /dev/null @@ -1,45 +0,0 @@ -# This file excludes paths from the Docker build context. -# -# By default, Docker's build context includes all files (and folders) in the -# current directory. Even if a file isn't copied into the container it is still sent to -# the Docker daemon. -# -# There are multiple reasons to exclude files from the build context: -# -# 1. Prevent nested folders from being copied into the container (ex: exclude -# /assets/node_modules when copying /assets) -# 2. Reduce the size of the build context and improve build time (ex. /build, /deps, /doc) -# 3. Avoid sending files containing sensitive information -# -# More information on using .dockerignore is available here: -# https://docs.docker.com/engine/reference/builder/#dockerignore-file - -.dockerignore - -# Ignore git, but keep git HEAD and refs to access current commit hash if needed: -# -# $ cat .git/HEAD | awk '{print ".git/"$2}' | xargs cat -# d0b8727759e1e0e7aa3d41707d12376e373d5ecc -.git -!.git/HEAD -!.git/refs - -# Common development/test artifacts -/cover/ -/doc/ -/test/ -/tmp/ -.elixir_ls - -# Mix artifacts -/_build/ -/deps/ -*.ez - -# Generated on crash by the VM -erl_crash.dump - -# Static artifacts - These should be fetched and built inside the Docker image -/assets/node_modules/ -/priv/static/assets/ -/priv/static/cache_manifest.json diff --git a/server-old/.formatter.exs b/server-old/.formatter.exs deleted file mode 100644 index 5971023f6b..0000000000 --- a/server-old/.formatter.exs +++ /dev/null @@ -1,5 +0,0 @@ -[ - import_deps: [:ecto, :ecto_sql, :phoenix], - subdirectories: ["priv/*/migrations"], - inputs: ["*.{ex,exs}", "{config,lib,test}/**/*.{ex,exs}", "priv/*/seeds.exs"] -] diff --git a/server-old/.gitignore b/server-old/.gitignore deleted file mode 100644 index 3faae0191a..0000000000 --- a/server-old/.gitignore +++ /dev/null @@ -1,27 +0,0 @@ -# The directory Mix will write compiled artifacts to. -/_build/ - -# If you run "mix test --cover", coverage assets end up here. -/cover/ - -# The directory Mix downloads your dependencies sources to. -/deps/ - -# Where 3rd-party dependencies like ExDoc output generated docs. -/doc/ - -# Ignore .fetch files in case you like to edit your project deps locally. -/.fetch - -# If the VM crashes, it generates a dump, let's ignore it too. -erl_crash.dump - -# Also ignore archive artifacts (built via "mix archive.build"). -*.ez - -# Temporary files, for example, from tests. -/tmp/ - -# Ignore package tarball (built via "mix hex.build"). -hypr-*.tar - diff --git a/server-old/.tool-versions b/server-old/.tool-versions deleted file mode 100644 index ce0360e0e4..0000000000 --- a/server-old/.tool-versions +++ /dev/null @@ -1,2 +0,0 @@ -erlang 27.0.1 -elixir 1.17.2-otp-27 diff --git a/server-old/Dockerfile b/server-old/Dockerfile deleted file mode 100644 index 764a8535b4..0000000000 --- a/server-old/Dockerfile +++ /dev/null @@ -1,92 +0,0 @@ -# Find eligible builder and runner images on Docker Hub. We use Ubuntu/Debian -# instead of Alpine to avoid DNS resolution issues in production. -# -# https://hub.docker.com/r/hexpm/elixir/tags?page=1&name=ubuntu -# https://hub.docker.com/_/ubuntu?tab=tags -# -# This file is based on these images: -# -# - https://hub.docker.com/r/hexpm/elixir/tags - for the build image -# - https://hub.docker.com/_/debian?tab=tags&page=1&name=bullseye-20240904-slim - for the release image -# - https://pkgs.org/ - resource for finding needed packages -# - Ex: hexpm/elixir:1.17.2-erlang-27.0.1-debian-bullseye-20240904-slim -# -ARG ELIXIR_VERSION=1.17.2 -ARG OTP_VERSION=27.0.1 -ARG DEBIAN_VERSION=bullseye-20240904-slim - -ARG BUILDER_IMAGE="hexpm/elixir:${ELIXIR_VERSION}-erlang-${OTP_VERSION}-debian-${DEBIAN_VERSION}" -ARG RUNNER_IMAGE="debian:${DEBIAN_VERSION}" - -FROM ${BUILDER_IMAGE} as builder - -# install build dependencies -RUN apt-get update -y && apt-get install -y build-essential git \ - && apt-get clean && rm -f /var/lib/apt/lists/*_* - -# prepare build dir -WORKDIR /app - -# install hex + rebar -RUN mix local.hex --force && \ - mix local.rebar --force - -# set build ENV -ENV MIX_ENV="prod" - -# install mix dependencies -COPY mix.exs mix.lock ./ -RUN mix deps.get --only $MIX_ENV -RUN mkdir config - -# copy compile-time config files before we compile dependencies -# to ensure any relevant config change will trigger the dependencies -# to be re-compiled. -COPY config/config.exs config/${MIX_ENV}.exs config/ -RUN mix deps.compile - -COPY priv priv - -COPY lib lib - -# Compile the release -RUN mix compile - -# Changes to config/runtime.exs don't require recompiling the code -COPY config/runtime.exs config/ - -COPY rel rel -RUN mix release - -# start a new build stage so that the final image will only contain -# the compiled release and other runtime necessities -FROM ${RUNNER_IMAGE} - -RUN apt-get update -y && \ - apt-get install -y libstdc++6 openssl libncurses5 locales ca-certificates \ - && apt-get clean && rm -f /var/lib/apt/lists/*_* - -# Set the locale -RUN sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && locale-gen - -ENV LANG en_US.UTF-8 -ENV LANGUAGE en_US:en -ENV LC_ALL en_US.UTF-8 - -WORKDIR "/app" -RUN chown nobody /app - -# set runner ENV -ENV MIX_ENV="prod" - -# Only copy the final release from the build stage -COPY --from=builder --chown=nobody:root /app/_build/${MIX_ENV}/rel/hypr ./ - -USER nobody - -# If using an environment that doesn't automatically reap zombie processes, it is -# advised to add an init process such as tini via `apt-get install` -# above and adding an entrypoint. See https://github.com/krallin/tini for details -# ENTRYPOINT ["/tini", "--"] - -CMD ["/app/bin/server"] diff --git a/server-old/README.md b/server-old/README.md deleted file mode 100644 index 76ac08ddc6..0000000000 --- a/server-old/README.md +++ /dev/null @@ -1 +0,0 @@ -# Server diff --git a/server-old/Taskfile.yaml b/server-old/Taskfile.yaml deleted file mode 100644 index 305782dbc0..0000000000 --- a/server-old/Taskfile.yaml +++ /dev/null @@ -1,12 +0,0 @@ -version: "3" -dotenv: - - .env -tasks: - fmt: mix format - dev: - cmds: - - docker-compose up -d - - sleep 2 - - mix ecto.migrate - - iex --sname hypr --cookie hypr -S mix phx.server - - docker-compose down diff --git a/server-old/config/config.exs b/server-old/config/config.exs deleted file mode 100644 index a1c051b06a..0000000000 --- a/server-old/config/config.exs +++ /dev/null @@ -1,35 +0,0 @@ -# This file is responsible for configuring your application -# and its dependencies with the aid of the Config module. -# -# This configuration file is loaded before any dependency and -# is restricted to this project. - -# General application configuration -import Config - -config :hypr, - ecto_repos: [Hypr.Repo], - generators: [timestamp_type: :utc_datetime] - -# Configures the endpoint -config :hypr, HyprWeb.Endpoint, - url: [host: "localhost"], - adapter: Bandit.PhoenixAdapter, - render_errors: [ - formats: [json: HyprWeb.ErrorJSON], - layout: false - ], - pubsub_server: Hypr.PubSub, - live_view: [signing_salt: "FGplErUX"] - -# Configures Elixir's Logger -config :logger, :console, - format: "$time $metadata[$level] $message\n", - metadata: [:request_id] - -# Use Jason for JSON parsing in Phoenix -config :phoenix, :json_library, Jason - -# Import environment specific config. This must remain at the bottom -# of this file so it overrides the configuration defined above. -import_config "#{config_env()}.exs" diff --git a/server-old/config/dev.exs b/server-old/config/dev.exs deleted file mode 100644 index 730760b637..0000000000 --- a/server-old/config/dev.exs +++ /dev/null @@ -1,63 +0,0 @@ -import Config - -# Configure your database -config :hypr, Hypr.Repo, - username: "postgres", - password: "postgres", - hostname: "localhost", - database: "hypr_dev", - stacktrace: true, - show_sensitive_data_on_connection_error: true, - pool_size: 10 - -# For development, we disable any cache and enable -# debugging and code reloading. -# -# The watchers configuration can be used to run external -# watchers to your application. For example, we can use it -# to bundle .js and .css sources. -config :hypr, HyprWeb.Endpoint, - # Binding to loopback ipv4 address prevents access from other machines. - # Change to `ip: {0, 0, 0, 0}` to allow access from other machines. - http: [ip: {127, 0, 0, 1}, port: 4000], - check_origin: false, - code_reloader: true, - debug_errors: true, - secret_key_base: "ayHrC/h6i0LMY7jpChPNqljJLFdb6KFs5AX6jWChWmtQdtUJ0ex58+6rC4JRHtDa", - watchers: [] - -# ## SSL Support -# -# In order to use HTTPS in development, a self-signed -# certificate can be generated by running the following -# Mix task: -# -# mix phx.gen.cert -# -# Run `mix help phx.gen.cert` for more information. -# -# The `http:` config above can be replaced with: -# -# https: [ -# port: 4001, -# cipher_suite: :strong, -# keyfile: "priv/cert/selfsigned_key.pem", -# certfile: "priv/cert/selfsigned.pem" -# ], -# -# If desired, both `http:` and `https:` keys can be -# configured to run both http and https servers on -# different ports. - -# Enable dev routes for dashboard and mailbox -config :hypr, dev_routes: true - -# Do not include metadata nor timestamps in development logs -config :logger, :console, format: "[$level] $message\n" - -# Set a higher stacktrace during development. Avoid configuring such -# in production as building large stacktraces may be expensive. -config :phoenix, :stacktrace_depth, 20 - -# Initialize plugs at runtime for faster development compilation -config :phoenix, :plug_init_mode, :runtime diff --git a/server-old/config/prod.exs b/server-old/config/prod.exs deleted file mode 100644 index 1fe2d9e854..0000000000 --- a/server-old/config/prod.exs +++ /dev/null @@ -1,7 +0,0 @@ -import Config - -# Do not print debug messages in production -config :logger, level: :info - -# Runtime production configuration, including reading -# of environment variables, is done on config/runtime.exs. diff --git a/server-old/config/runtime.exs b/server-old/config/runtime.exs deleted file mode 100644 index 3dc67f1718..0000000000 --- a/server-old/config/runtime.exs +++ /dev/null @@ -1,97 +0,0 @@ -import Config - -# config/runtime.exs is executed for all environments, including -# during releases. It is executed after compilation and before the -# system starts, so it is typically used to load production configuration -# and secrets from environment variables or elsewhere. Do not define -# any compile-time configuration in here, as it won't be applied. -# The block below contains prod specific runtime configuration. - -# ## Using releases -# -# If you use `mix release`, you need to explicitly enable the server -# by passing the PHX_SERVER=true when you start it: -# -# PHX_SERVER=true bin/hypr start -# -# Alternatively, you can use `mix phx.gen.release` to generate a `bin/server` -# script that automatically sets the env var above. -if System.get_env("PHX_SERVER") do - config :hypr, HyprWeb.Endpoint, server: true -end - -if config_env() == :prod do - database_url = - System.get_env("DATABASE_URL") || - raise """ - environment variable DATABASE_URL is missing. - For example: ecto://USER:PASS@HOST/DATABASE - """ - - config :hypr, Hypr.Repo, - url: database_url, - pool_size: String.to_integer(System.get_env("POOL_SIZE") || "10"), - ssl: [cacerts: :public_key.cacerts_get()], - socket_options: [:inet6] - - # The secret key base is used to sign/encrypt cookies and other secrets. - # A default value is used in config/dev.exs and config/test.exs but you - # want to use a different value for prod and you most likely don't want - # to check this value into version control, so we use an environment - # variable instead. - secret_key_base = - System.get_env("SECRET_KEY_BASE") || - raise """ - environment variable SECRET_KEY_BASE is missing. - You can generate one by calling: mix phx.gen.secret - """ - - host = System.get_env("PHX_HOST") || "example.com" - port = String.to_integer(System.get_env("PORT") || "4000") - - config :hypr, :dns_cluster_query, System.get_env("DNS_CLUSTER_QUERY") - - config :hypr, HyprWeb.Endpoint, - url: [host: host, port: 443, scheme: "https"], - http: [ - # Enable IPv6 and bind on all interfaces. - # Set it to {0, 0, 0, 0, 0, 0, 0, 1} for local network only access. - # See the documentation on https://hexdocs.pm/bandit/Bandit.html#t:options/0 - # for details about using IPv6 vs IPv4 and loopback vs public addresses. - ip: {0, 0, 0, 0, 0, 0, 0, 0}, - port: port - ], - secret_key_base: secret_key_base - - # ## SSL Support - # - # To get SSL working, you will need to add the `https` key - # to your endpoint configuration: - # - # config :hypr, HyprWeb.Endpoint, - # https: [ - # ..., - # port: 443, - # cipher_suite: :strong, - # keyfile: System.get_env("SOME_APP_SSL_KEY_PATH"), - # certfile: System.get_env("SOME_APP_SSL_CERT_PATH") - # ] - # - # The `cipher_suite` is set to `:strong` to support only the - # latest and more secure SSL ciphers. This means old browsers - # and clients may not be supported. You can set it to - # `:compatible` for wider support. - # - # `:keyfile` and `:certfile` expect an absolute path to the key - # and cert in disk or a relative path inside priv, for example - # "priv/ssl/server.key". For all supported SSL configuration - # options, see https://hexdocs.pm/plug/Plug.SSL.html#configure/1 - # - # We also recommend setting `force_ssl` in your config/prod.exs, - # ensuring no data is ever sent via http, always redirecting to https: - # - # config :hypr, HyprWeb.Endpoint, - # force_ssl: [hsts: true] - # - # Check `Plug.SSL` for all available options in `force_ssl`. -end diff --git a/server-old/config/test.exs b/server-old/config/test.exs deleted file mode 100644 index d990333101..0000000000 --- a/server-old/config/test.exs +++ /dev/null @@ -1,27 +0,0 @@ -import Config - -# Configure your database -# -# The MIX_TEST_PARTITION environment variable can be used -# to provide built-in test partitioning in CI environment. -# Run `mix help test` for more information. -config :hypr, Hypr.Repo, - username: "postgres", - password: "postgres", - hostname: "localhost", - database: "hypr_test#{System.get_env("MIX_TEST_PARTITION")}", - pool: Ecto.Adapters.SQL.Sandbox, - pool_size: System.schedulers_online() * 2 - -# We don't run a server during test. If one is required, -# you can enable the server option below. -config :hypr, HyprWeb.Endpoint, - http: [ip: {127, 0, 0, 1}, port: 4002], - secret_key_base: "nbBYr1GEmPnhQsSxJMiN/It9IZ8kDg4mFiU41Q268fnRlAV3BZld7XU5AA6gfbNz", - server: false - -# Print only warnings and errors during test -config :logger, level: :warning - -# Initialize plugs at runtime for faster test compilation -config :phoenix, :plug_init_mode, :runtime diff --git a/server-old/debug.sh b/server-old/debug.sh deleted file mode 100644 index a1d039af5c..0000000000 --- a/server-old/debug.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash - -set -e - -fly ssh console --pty --select -C "/app/bin/hypr remote" diff --git a/server-old/docker-compose.yaml b/server-old/docker-compose.yaml deleted file mode 100644 index 69efdbf7e4..0000000000 --- a/server-old/docker-compose.yaml +++ /dev/null @@ -1,10 +0,0 @@ -name: hypr -services: - db: - image: postgres:16 - environment: - POSTGRES_USER: postgres - POSTGRES_PASSWORD: postgres - POSTGRES_DB: hypr_dev - ports: - - 5432:5432 diff --git a/server-old/fly.toml b/server-old/fly.toml deleted file mode 100644 index c925b6350b..0000000000 --- a/server-old/fly.toml +++ /dev/null @@ -1,42 +0,0 @@ -# fly.toml app configuration file generated for hypr-server on 2024-12-16T14:14:08+09:00 -# -# See https://fly.io/docs/reference/configuration/ for information about how to use this file. -# - -app = 'hypr-server' -primary_region = 'sjc' -kill_signal = 'SIGTERM' - -[build] - -[deploy] - release_command = '/app/bin/migrate' - -[env] - PHX_HOST = 'server.hyprnote.com' - PORT = '8080' - -[http_service] - internal_port = 8080 - force_https = true - auto_stop_machines = 'stop' - auto_start_machines = true - min_machines_running = 1 - processes = ['app'] - - [http_service.concurrency] - type = 'connections' - hard_limit = 1000 - soft_limit = 1000 - -[[http_service.checks]] - grace_period = "10s" - interval = "30s" - method = "GET" - path = "/health" - timeout = "5s" - -[[vm]] - memory = '1gb' - cpu_kind = 'shared' - cpus = 1 diff --git a/server-old/lib/hypr.ex b/server-old/lib/hypr.ex deleted file mode 100644 index ef4a5c2ed4..0000000000 --- a/server-old/lib/hypr.ex +++ /dev/null @@ -1,9 +0,0 @@ -defmodule Hypr do - @moduledoc """ - Hypr keeps the contexts that define your domain - and business logic. - - Contexts are also responsible for managing your data, regardless - if it comes from the database, an external API or others. - """ -end diff --git a/server-old/lib/hypr/application.ex b/server-old/lib/hypr/application.ex deleted file mode 100644 index b9c1091317..0000000000 --- a/server-old/lib/hypr/application.ex +++ /dev/null @@ -1,40 +0,0 @@ -defmodule Hypr.Application do - # See https://hexdocs.pm/elixir/Application.html - # for more information on OTP Applications - @moduledoc false - - use Application - - @impl true - def start(_type, _args) do - children = - [ - HyprWeb.Telemetry, - Hypr.Repo, - {DNSCluster, query: Application.get_env(:hypr, :dns_cluster_query) || :ignore}, - {Phoenix.PubSub, name: Hypr.PubSub} - ] ++ stripe() ++ [HyprWeb.Endpoint] - - # See https://hexdocs.pm/elixir/Supervisor.html - # for other strategies and supported options - opts = [strategy: :one_for_one, name: Hypr.Supervisor] - Supervisor.start_link(children, opts) - end - - defp stripe() do - if Application.get_env(:hypr, :dev_routes, false) and - Phoenix.Endpoint.server?(:hypr, HyprWeb.Endpoint) do - [{Hypr.StripeWebhookListener, [forward_to: "http://localhost:4000/webhook/stripe"]}] - else - [] - end - end - - # Tell Phoenix to update the endpoint configuration - # whenever the application is updated. - @impl true - def config_change(changed, _new, removed) do - HyprWeb.Endpoint.config_change(changed, removed) - :ok - end -end diff --git a/server-old/lib/hypr/release.ex b/server-old/lib/hypr/release.ex deleted file mode 100644 index 9edb19e56e..0000000000 --- a/server-old/lib/hypr/release.ex +++ /dev/null @@ -1,28 +0,0 @@ -defmodule Hypr.Release do - @moduledoc """ - Used for executing DB release tasks when run in production without Mix - installed. - """ - @app :hypr - - def migrate do - load_app() - - for repo <- repos() do - {:ok, _, _} = Ecto.Migrator.with_repo(repo, &Ecto.Migrator.run(&1, :up, all: true)) - end - end - - def rollback(repo, version) do - load_app() - {:ok, _, _} = Ecto.Migrator.with_repo(repo, &Ecto.Migrator.run(&1, :down, to: version)) - end - - defp repos do - Application.fetch_env!(@app, :ecto_repos) - end - - defp load_app do - Application.load(@app) - end -end diff --git a/server-old/lib/hypr/repo.ex b/server-old/lib/hypr/repo.ex deleted file mode 100644 index 41f251167c..0000000000 --- a/server-old/lib/hypr/repo.ex +++ /dev/null @@ -1,5 +0,0 @@ -defmodule Hypr.Repo do - use Ecto.Repo, - otp_app: :hypr, - adapter: Ecto.Adapters.Postgres -end diff --git a/server-old/lib/hypr/stripe_webhook_listener.ex b/server-old/lib/hypr/stripe_webhook_listener.ex deleted file mode 100644 index 3faa778dca..0000000000 --- a/server-old/lib/hypr/stripe_webhook_listener.ex +++ /dev/null @@ -1,60 +0,0 @@ -defmodule Hypr.StripeWebhookListener do - use GenServer - require Logger - - def start_link(options) do - {stripe_cli, options} = Keyword.pop(options, :stripe_cli, System.find_executable("stripe")) - {forward_to, options} = Keyword.pop!(options, :forward_to) - options = Keyword.validate!(options, [:name, :timeout, :debug, :spawn_opt, :hibernate_after]) - GenServer.start_link(__MODULE__, %{stripe_cli: stripe_cli, forward_to: forward_to}, options) - end - - @impl true - def init(%{stripe_cli: nil}) do - Logger.warning("Stripe CLI not found") - :ignore - end - - def init(%{stripe_cli: stripe_cli, forward_to: forward_to}) do - # https://docs.stripe.com/cli/listen - args = [ - "listen", - "--skip-verify", - "--forward-to", - forward_to - ] - - port = - Port.open( - {:spawn_executable, stripe_cli}, - [ - :binary, - :stderr_to_stdout, - line: 2048, - args: args - ] - ) - - {:ok, port} - end - - @impl true - def handle_info({port, {:data, {:eol, line}}}, port) do - secret = extract_secret(line) - - if is_nil(secret) do - Logger.info("stripe: #{line}") - else - Application.put_env(:hypr, :stripe_webhook_secret, secret) - end - - {:noreply, port} - end - - defp extract_secret(text) do - case Regex.run(~r/webhook signing secret is (whsec_[a-f0-9]{64})/, text) do - [_, secret] -> secret - _ -> nil - end - end -end diff --git a/server-old/lib/hypr/stt/deepgram.ex b/server-old/lib/hypr/stt/deepgram.ex deleted file mode 100644 index 9daf4233be..0000000000 --- a/server-old/lib/hypr/stt/deepgram.ex +++ /dev/null @@ -1,119 +0,0 @@ -# https://developers.deepgram.com/docs/lower-level-websockets - -defmodule Hypr.STT.Streaming.Deepgram do - @behaviour Hypr.STT.Streaming - - use WebSockex - - @impl Hypr.STT.Streaming - def start_link(%{handle_stt: _} = state) do - params = - %{ - # https://developers.deepgram.com/docs/model - model: "nova-2-general", - # https://developers.deepgram.com/docs/speech-started - vad_events: true, - # https://developers.deepgram.com/docs/utterance-end - utterance_end_ms: 1000, - interim_results: true, - # https://developers.deepgram.com/docs/endpointing - # https://developers.deepgram.com/docs/understand-endpointing-interim-results#controlling-endpointing - endpointing: 20, - # https://developers.deepgram.com/docs/filler-words - filler_words: true - } - |> Map.merge(%{ - # https://developers.deepgram.com/docs/encoding - encoding: "linear16", - sample_rate: 16000 - }) - - # https://developers.deepgram.com/reference/listen-live - url = - URI.new!("wss://api.deepgram.com") - |> URI.append_path("/v1/listen") - |> URI.append_query(URI.encode_query(params)) - |> URI.to_string() - - # https://developers.deepgram.com/docs/authentication - api_key = Application.fetch_env!(:hypr, :deepgram_api_key) - headers = [{"Authorization", "Token #{api_key}"}] - - state = - state - |> Map.put(:speaking?, false) - |> Map.put(:vad_queue, Queue.new(2)) - - with {:ok, pid} <- WebSockex.start_link(url, __MODULE__, state, extra_headers: headers) do - Process.send_after(pid, :keep_alive, 3000) - {:ok, pid} - end - end - - @impl Hypr.STT.Streaming - def send_audio(pid, audio, _opts \\ []) do - WebSockex.cast(pid, {:audio, audio}) - end - - @impl WebSockex - def handle_cast({:audio, audio}, state) do - # https://developers.deepgram.com/reference/listen-live#sending-audio-data - {:reply, {:binary, audio}, state} - end - - @impl WebSockex - def handle_frame({:text, data}, state), do: handle_in(Jason.decode!(data), state) - - # https://developers.deepgram.com/reference/listen-live#response-schema - # https://developers.deepgram.com/docs/understand-endpointing-interim-results - # https://developers.deepgram.com/docs/understanding-end-of-speech-detection - defp handle_in( - %{ - "type" => "Results", - "is_final" => _is_final, - "speech_final" => _speech_final, - "channel" => %{"alternatives" => [%{"transcript" => transcript} | _]} - }, - state - ) do - if not state.speaking? do - state.handle_stt.({:transcript, transcript}) - state.handle_stt.(:utterance_end) - {:ok, Map.put(state, :speaking?, false)} - else - {:ok, state} - end - end - - # https://developers.deepgram.com/docs/speech-started - defp handle_in(%{"type" => "SpeechStarted"}, state), do: {:ok, state} - - # https://developers.deepgram.com/docs/utterance-end - defp handle_in(%{"type" => "UtteranceEnd"}, state), do: {:ok, state} - - defp handle_in(_, state), do: {:ok, state} - - # https://developers.deepgram.com/docs/audio-keep-alive#sending-keepalive - @impl WebSockex - def handle_info(:keep_alive, state) do - Process.send_after(self(), :keep_alive, 3000) - - msg = Jason.encode!(%{type: "KeepAlive"}) - {:reply, {:text, msg}, state} - end - - # https://developers.deepgram.com/docs/finalize - def handle_info(:flush, state) do - msg = Jason.encode!(%{type: "Finalize"}) - {:reply, {:text, msg}, state} - end - - @impl WebSockex - def terminate(reason, state) do - IO.inspect(reason) - - # https://developers.deepgram.com/docs/close-stream - msg = Jason.encode!(%{type: "CloseStream"}) - {:reply, {:text, msg}, state} - end -end diff --git a/server-old/lib/hypr/stt/stt.ex b/server-old/lib/hypr/stt/stt.ex deleted file mode 100644 index cf44080ab0..0000000000 --- a/server-old/lib/hypr/stt/stt.ex +++ /dev/null @@ -1,7 +0,0 @@ -defmodule Hypr.STT.Streaming do - @callback send_audio(pid(), binary(), keyword()) :: :ok | {:error, any()} - - def child_spec(arg), do: impl().child_spec(arg) - def send_audio(client, audio, opts \\ []), do: impl().send_audio(client, audio, opts) - def impl(), do: Application.get_env(:hypr, :stt_streaming, Hypr.STT.Streaming.Deepgram) -end diff --git a/server-old/lib/hypr_web.ex b/server-old/lib/hypr_web.ex deleted file mode 100644 index 1b4a39a5c2..0000000000 --- a/server-old/lib/hypr_web.ex +++ /dev/null @@ -1,65 +0,0 @@ -defmodule HyprWeb do - @moduledoc """ - The entrypoint for defining your web interface, such - as controllers, components, channels, and so on. - - This can be used in your application as: - - use HyprWeb, :controller - use HyprWeb, :html - - The definitions below will be executed for every controller, - component, etc, so keep them short and clean, focused - on imports, uses and aliases. - - Do NOT define functions inside the quoted expressions - below. Instead, define additional modules and import - those modules here. - """ - - def static_paths, do: ~w(assets fonts images favicon.ico robots.txt) - - def router do - quote do - use Phoenix.Router, helpers: false - - # Import common connection and controller functions to use in pipelines - import Plug.Conn - import Phoenix.Controller - end - end - - def channel do - quote do - use Phoenix.Channel - end - end - - def controller do - quote do - use Phoenix.Controller, - formats: [:html, :json], - layouts: [html: HyprWeb.Layouts] - - import Plug.Conn - - unquote(verified_routes()) - end - end - - def verified_routes do - quote do - use Phoenix.VerifiedRoutes, - endpoint: HyprWeb.Endpoint, - router: HyprWeb.Router, - statics: HyprWeb.static_paths() - end - end - - @doc """ - When used, dispatch to the appropriate controller/live_view/etc. - """ - defmacro __using__(which) when is_atom(which) do - apply(__MODULE__, which, []) - end -end diff --git a/server-old/lib/hypr_web/controllers/error_json.ex b/server-old/lib/hypr_web/controllers/error_json.ex deleted file mode 100644 index 47ea640d79..0000000000 --- a/server-old/lib/hypr_web/controllers/error_json.ex +++ /dev/null @@ -1,21 +0,0 @@ -defmodule HyprWeb.ErrorJSON do - @moduledoc """ - This module is invoked by your endpoint in case of errors on JSON requests. - - See config/config.exs. - """ - - # If you want to customize a particular status code, - # you may add your own clauses, such as: - # - # def render("500.json", _assigns) do - # %{errors: %{detail: "Internal Server Error"}} - # end - - # By default, Phoenix returns the status message from - # the template name. For example, "404.json" becomes - # "Not Found". - def render(template, _assigns) do - %{errors: %{detail: Phoenix.Controller.status_message_from_template(template)}} - end -end diff --git a/server-old/lib/hypr_web/endpoint.ex b/server-old/lib/hypr_web/endpoint.ex deleted file mode 100644 index e936cc9413..0000000000 --- a/server-old/lib/hypr_web/endpoint.ex +++ /dev/null @@ -1,53 +0,0 @@ -defmodule HyprWeb.Endpoint do - use Phoenix.Endpoint, otp_app: :hypr - - # The session will be stored in the cookie and signed, - # this means its contents can be read but not tampered with. - # Set :encryption_salt if you would also like to encrypt it. - @session_options [ - store: :cookie, - key: "_hypr_key", - signing_salt: "Z/RHYM4E", - same_site: "Lax" - ] - - plug HyprWeb.Plugs.Health - - socket "/v0/conversation", HyprWeb.Session, - websocket: [path: "/"], - longpoll: false - - # socket "/live", Phoenix.LiveView.Socket, - # websocket: [connect_info: [session: @session_options]], - # longpoll: [connect_info: [session: @session_options]] - - # Serve at "/" the static files from "priv/static" directory. - # - # You should set gzip to true if you are running phx.digest - # when deploying your static files in production. - plug Plug.Static, - at: "/", - from: :hypr, - gzip: false, - only: HyprWeb.static_paths() - - # Code reloading can be explicitly enabled under the - # :code_reloader configuration of your endpoint. - if code_reloading? do - plug Phoenix.CodeReloader - plug Phoenix.Ecto.CheckRepoStatus, otp_app: :hypr - end - - plug Plug.RequestId - plug Plug.Telemetry, event_prefix: [:phoenix, :endpoint] - - plug Plug.Parsers, - parsers: [:urlencoded, :multipart, :json], - pass: ["*/*"], - json_decoder: Phoenix.json_library() - - plug Plug.MethodOverride - plug Plug.Head - plug Plug.Session, @session_options - plug HyprWeb.Router -end diff --git a/server-old/lib/hypr_web/plugs/health.ex b/server-old/lib/hypr_web/plugs/health.ex deleted file mode 100644 index 8aa5df9d82..0000000000 --- a/server-old/lib/hypr_web/plugs/health.ex +++ /dev/null @@ -1,25 +0,0 @@ -defmodule HyprWeb.Plugs.Health do - import Plug.Conn - - def init(opts), do: opts - - def call(%Plug.Conn{request_path: "/health"} = conn, _opts) do - [db?()] - |> Enum.all?() - |> case do - true -> conn |> send_resp(200, "OK") |> halt() - false -> conn |> send_resp(500, "") |> halt() - end - end - - def call(conn, _opts), do: conn - - defp db?() do - try do - Ecto.Adapters.SQL.query(Hypr.Repo, "select 1", []) - :ok - rescue - DBConnection.ConnectionError -> :error - end - end -end diff --git a/server-old/lib/hypr_web/router.ex b/server-old/lib/hypr_web/router.ex deleted file mode 100644 index 4223f5063c..0000000000 --- a/server-old/lib/hypr_web/router.ex +++ /dev/null @@ -1,11 +0,0 @@ -defmodule HyprWeb.Router do - use HyprWeb, :router - - pipeline :api do - plug :accepts, ["json"] - end - - scope "/api", HyprWeb do - pipe_through :api - end -end diff --git a/server-old/lib/hypr_web/session.ex b/server-old/lib/hypr_web/session.ex deleted file mode 100644 index 650f66a74a..0000000000 --- a/server-old/lib/hypr_web/session.ex +++ /dev/null @@ -1,75 +0,0 @@ -defmodule HyprWeb.Session do - @behaviour Phoenix.Socket.Transport - - @impl Phoenix.Socket.Transport - def child_spec(_opts), do: :ignore - - @impl Phoenix.Socket.Transport - def connect(state), do: {:ok, state} - - @impl Phoenix.Socket.Transport - def init(state) do - state = - state - |> Map.put(:supervisor_pid, nil) - - {:ok, state} - end - - @impl Phoenix.Socket.Transport - def handle_in({_, _opts}, state) do - state = - state - |> Map.put(:supervisor_pid, start_supervisor()) - - {:ok, state} - end - - @impl Phoenix.Socket.Transport - def handle_info({:stt, {:transcript, text}}, state) do - {:ok, state} - end - - @impl Phoenix.Socket.Transport - def handle_info(_, state) do - {:ok, state} - end - - @impl Phoenix.Socket.Transport - def terminate(:remote, _state), do: :ok - def terminate({:error, :closed}, _state), do: :ok - def terminate({:error, :idle}, _state), do: :ok - def terminate({:error, :supervisor_died}, _state), do: :ok - - def terminate(e, _state) do - IO.inspect(e) - :ok - end - - defp start_supervisor() do - here = self() - - {:ok, pid} = - Supervisor.start_link(HyprWeb.Session.Supervisor, - strategy: :one_for_one, - handle_stt: &send(here, {:stt, &1}) - ) - - pid - end -end - -defmodule HyprWeb.Session.Supervisor do - use Supervisor - - def start_link(opts) do - Supervisor.start_link(__MODULE__, opts) - end - - def init(opts) do - {handle_stt, opts} = Keyword.pop(opts, :handle_stt, &IO.inspect/1) - - children = [{Hypr.STT.Streaming, %{handle_stt: handle_stt}}] - Supervisor.init(children, opts) - end -end diff --git a/server-old/lib/hypr_web/stripe_webhook_handler.ex b/server-old/lib/hypr_web/stripe_webhook_handler.ex deleted file mode 100644 index 0d690d56be..0000000000 --- a/server-old/lib/hypr_web/stripe_webhook_handler.ex +++ /dev/null @@ -1,28 +0,0 @@ -# https://docs.stripe.com/billing/subscriptions/webhooks#events -defmodule HyprWeb.StripeWebhookHandler do - @behaviour Stripe.WebhookHandler - require Logger - - @impl true - def handle_event(%Stripe.Event{type: type, data: data}) - when type in ["customer.created", "customer.updated"] do - %{object: %Stripe.Customer{} = _customer} = data - - :ok - end - - @impl true - def handle_event(%Stripe.Event{type: type, data: data}) - when type in [ - "customer.subscription.created", - "customer.subscription.updated", - "customer.subscription.deleted" - ] do - %{object: %Stripe.Subscription{customer: _id} = _subscription} = data - - :ok - end - - @impl true - def handle_event(_event), do: :ok -end diff --git a/server-old/lib/hypr_web/telemetry.ex b/server-old/lib/hypr_web/telemetry.ex deleted file mode 100644 index fcde974181..0000000000 --- a/server-old/lib/hypr_web/telemetry.ex +++ /dev/null @@ -1,92 +0,0 @@ -defmodule HyprWeb.Telemetry do - use Supervisor - import Telemetry.Metrics - - def start_link(arg) do - Supervisor.start_link(__MODULE__, arg, name: __MODULE__) - end - - @impl true - def init(_arg) do - children = [ - # Telemetry poller will execute the given period measurements - # every 10_000ms. Learn more here: https://hexdocs.pm/telemetry_metrics - {:telemetry_poller, measurements: periodic_measurements(), period: 10_000} - # Add reporters as children of your supervision tree. - # {Telemetry.Metrics.ConsoleReporter, metrics: metrics()} - ] - - Supervisor.init(children, strategy: :one_for_one) - end - - def metrics do - [ - # Phoenix Metrics - summary("phoenix.endpoint.start.system_time", - unit: {:native, :millisecond} - ), - summary("phoenix.endpoint.stop.duration", - unit: {:native, :millisecond} - ), - summary("phoenix.router_dispatch.start.system_time", - tags: [:route], - unit: {:native, :millisecond} - ), - summary("phoenix.router_dispatch.exception.duration", - tags: [:route], - unit: {:native, :millisecond} - ), - summary("phoenix.router_dispatch.stop.duration", - tags: [:route], - unit: {:native, :millisecond} - ), - summary("phoenix.socket_connected.duration", - unit: {:native, :millisecond} - ), - summary("phoenix.channel_joined.duration", - unit: {:native, :millisecond} - ), - summary("phoenix.channel_handled_in.duration", - tags: [:event], - unit: {:native, :millisecond} - ), - - # Database Metrics - summary("hypr.repo.query.total_time", - unit: {:native, :millisecond}, - description: "The sum of the other measurements" - ), - summary("hypr.repo.query.decode_time", - unit: {:native, :millisecond}, - description: "The time spent decoding the data received from the database" - ), - summary("hypr.repo.query.query_time", - unit: {:native, :millisecond}, - description: "The time spent executing the query" - ), - summary("hypr.repo.query.queue_time", - unit: {:native, :millisecond}, - description: "The time spent waiting for a database connection" - ), - summary("hypr.repo.query.idle_time", - unit: {:native, :millisecond}, - description: - "The time the connection spent waiting before being checked out for the query" - ), - - # VM Metrics - summary("vm.memory.total", unit: {:byte, :kilobyte}), - summary("vm.total_run_queue_lengths.total"), - summary("vm.total_run_queue_lengths.cpu"), - summary("vm.total_run_queue_lengths.io") - ] - end - - defp periodic_measurements do - [ - # A module, function and arguments to be invoked periodically. - # This function must call :telemetry.execute/3 and a metric must be added above. - # {HyprWeb, :count_users, []} - ] - end -end diff --git a/server-old/lib/proto/v0.pb.ex b/server-old/lib/proto/v0.pb.ex deleted file mode 100644 index ae3b3d16b5..0000000000 --- a/server-old/lib/proto/v0.pb.ex +++ /dev/null @@ -1,15 +0,0 @@ -defmodule Hypr.V0.TranscribeInputChunk do - @moduledoc false - - use Protobuf, syntax: :proto3, protoc_gen_elixir_version: "0.13.0" - - field :audio, 1, type: :bytes -end - -defmodule Hypr.V0.TranscribeOutputChunk do - @moduledoc false - - use Protobuf, syntax: :proto3, protoc_gen_elixir_version: "0.13.0" - - field :text, 1, type: :string -end diff --git a/server-old/mix.exs b/server-old/mix.exs deleted file mode 100644 index 2cea22c503..0000000000 --- a/server-old/mix.exs +++ /dev/null @@ -1,76 +0,0 @@ -defmodule Hypr.MixProject do - use Mix.Project - - def project do - [ - app: :hypr, - version: "0.1.0", - elixir: "~> 1.14", - elixirc_paths: elixirc_paths(Mix.env()), - start_permanent: Mix.env() == :prod, - aliases: aliases(), - deps: deps() - ] - end - - # Configuration for the OTP application. - # - # Type `mix help compile.app` for more information. - def application do - [ - mod: {Hypr.Application, []}, - extra_applications: [:logger, :runtime_tools] - ] - end - - # Specifies which paths to compile per environment. - defp elixirc_paths(:test), do: ["lib", "test/support"] - defp elixirc_paths(_), do: ["lib"] - - # Specifies your project dependencies. - # - # Type `mix help deps` for examples and options. - defp deps do - [ - {:phoenix, "~> 1.7.14"}, - {:phoenix_ecto, "~> 4.5"}, - {:ecto_sql, "~> 3.10"}, - {:postgrex, ">= 0.0.0"}, - {:telemetry_metrics, "~> 1.0"}, - {:telemetry_poller, "~> 1.0"}, - {:jason, "~> 1.2"}, - {:dns_cluster, "~> 0.1.1"}, - {:bandit, "~> 1.5"}, - # - {:ash, "~> 3.4"}, - {:ash_postgres, "~> 2.4"}, - {:ash_json_api, "~> 1.4"}, - # - {:req, "~> 0.5.0"}, - {:retry, "~> 0.18"}, - {:sentry, "~> 10.8"}, - {:hackney, "~> 1.8"}, - {:ex2ms, "~> 1.7"}, - {:recon, "~> 2.5", override: true}, - {:recon_ex, github: "tatsuya6502/recon_ex", ref: "0ce4c5d"}, - {:protobuf, "~> 0.13.0"}, - {:stripity_stripe, "~> 3.2"}, - {:websockex, "~> 0.4.3"} - ] - end - - # Aliases are shortcuts or tasks specific to the current project. - # For example, to install project dependencies and perform other setup tasks, run: - # - # $ mix setup - # - # See the documentation for `Mix` for more info on aliases. - defp aliases do - [ - setup: ["deps.get", "ecto.setup"], - "ecto.setup": ["ecto.create", "ecto.migrate", "run priv/repo/seeds.exs"], - "ecto.reset": ["ecto.drop", "ecto.setup"], - test: ["ecto.create --quiet", "ecto.migrate --quiet", "test"] - ] - end -end diff --git a/server-old/mix.lock b/server-old/mix.lock deleted file mode 100644 index 274cadf6cb..0000000000 --- a/server-old/mix.lock +++ /dev/null @@ -1,70 +0,0 @@ -%{ - "ash": {:hex, :ash, "3.4.46", "24286834d87719a8d9e0d1addf4b5be4c2acca30c554dbd5d66229d04748a15d", [:mix], [{:decimal, "~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:ecto, "~> 3.7", [hex: :ecto, repo: "hexpm", optional: false]}, {:ets, "~> 0.8", [hex: :ets, repo: "hexpm", optional: false]}, {:igniter, ">= 0.4.8 and < 1.0.0-0", [hex: :igniter, repo: "hexpm", optional: false]}, {:jason, ">= 1.0.0", [hex: :jason, repo: "hexpm", optional: false]}, {:owl, "~> 0.11", [hex: :owl, repo: "hexpm", optional: false]}, {:picosat_elixir, "~> 0.2", [hex: :picosat_elixir, repo: "hexpm", optional: true]}, {:plug, ">= 0.0.0", [hex: :plug, repo: "hexpm", optional: true]}, {:reactor, "~> 0.9", [hex: :reactor, repo: "hexpm", optional: false]}, {:simple_sat, ">= 0.1.1 and < 1.0.0-0", [hex: :simple_sat, repo: "hexpm", optional: true]}, {:spark, ">= 2.2.29 and < 3.0.0-0", [hex: :spark, repo: "hexpm", optional: false]}, {:splode, ">= 0.2.6 and < 1.0.0-0", [hex: :splode, repo: "hexpm", optional: false]}, {:stream_data, "~> 1.0", [hex: :stream_data, repo: "hexpm", optional: false]}, {:telemetry, "~> 1.1", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "78cd7d1d3ef27516f88a503e181c8e050f80d93222d76696d7491b200bd606db"}, - "ash_json_api": {:hex, :ash_json_api, "1.4.13", "4667094c107a306e0dcf6149f96da4dc33cbec145db5fdf0d20d29b3e31be8e2", [:mix], [{:ash, "~> 3.3", [hex: :ash, repo: "hexpm", optional: false]}, {:igniter, ">= 0.3.58 and < 1.0.0-0", [hex: :igniter, repo: "hexpm", optional: false]}, {:jason, "~> 1.1", [hex: :jason, repo: "hexpm", optional: false]}, {:json_xema, "~> 0.4", [hex: :json_xema, repo: "hexpm", optional: false]}, {:open_api_spex, "~> 3.16", [hex: :open_api_spex, repo: "hexpm", optional: true]}, {:plug, "~> 1.11", [hex: :plug, repo: "hexpm", optional: false]}, {:spark, ">= 2.2.10 and < 3.0.0-0", [hex: :spark, repo: "hexpm", optional: false]}], "hexpm", "237fd78dd346d3efdc2fcd811d0c4b9a55d07e43572011196b8639db22b19763"}, - "ash_postgres": {:hex, :ash_postgres, "2.4.16", "cb45c71e144590288a8f7cea9573a62e34cd0cbba1b0a9b073da1483caa87086", [:mix], [{:ash, ">= 3.4.44 and < 4.0.0-0", [hex: :ash, repo: "hexpm", optional: false]}, {:ash_sql, ">= 0.2.40 and < 1.0.0-0", [hex: :ash_sql, repo: "hexpm", optional: false]}, {:ecto, ">= 3.12.1 and < 4.0.0-0", [hex: :ecto, repo: "hexpm", optional: false]}, {:ecto_sql, "~> 3.12", [hex: :ecto_sql, repo: "hexpm", optional: false]}, {:igniter, ">= 0.4.4 and < 1.0.0-0", [hex: :igniter, repo: "hexpm", optional: false]}, {:inflex, "~> 2.1", [hex: :inflex, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}, {:owl, "~> 0.11", [hex: :owl, repo: "hexpm", optional: false]}, {:postgrex, ">= 0.0.0", [hex: :postgrex, repo: "hexpm", optional: false]}], "hexpm", "71bc13fbcb39abd71fc1b8312be9e14c7733688e308d1d2bc21cfb54c8b40098"}, - "ash_sql": {:hex, :ash_sql, "0.2.41", "9e0a1686dc67a7cdc8435ced6c998dcd4de87980dde0a72d77946bbc9d1e65cb", [:mix], [{:ash, ">= 3.1.7 and < 4.0.0-0", [hex: :ash, repo: "hexpm", optional: false]}, {:ecto, "~> 3.9", [hex: :ecto, repo: "hexpm", optional: false]}, {:ecto_sql, "~> 3.9", [hex: :ecto_sql, repo: "hexpm", optional: false]}], "hexpm", "226470dc8eeb3e89f98c0fb4ef11edf1b114e1caf3cd3457af7f9481df8221e8"}, - "bandit": {:hex, :bandit, "1.6.1", "9e01b93d72ddc21d8c576a704949e86ee6cde7d11270a1d3073787876527a48f", [:mix], [{:hpax, "~> 1.0", [hex: :hpax, repo: "hexpm", optional: false]}, {:plug, "~> 1.14", [hex: :plug, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}, {:thousand_island, "~> 1.0", [hex: :thousand_island, repo: "hexpm", optional: false]}, {:websock, "~> 0.5", [hex: :websock, repo: "hexpm", optional: false]}], "hexpm", "5a904bf010ea24b67979835e0507688e31ac873d4ffc8ed0e5413e8d77455031"}, - "castore": {:hex, :castore, "1.0.10", "43bbeeac820f16c89f79721af1b3e092399b3a1ecc8df1a472738fd853574911", [:mix], [], "hexpm", "1b0b7ea14d889d9ea21202c43a4fa015eb913021cb535e8ed91946f4b77a8848"}, - "certifi": {:hex, :certifi, "2.12.0", "2d1cca2ec95f59643862af91f001478c9863c2ac9cb6e2f89780bfd8de987329", [:rebar3], [], "hexpm", "ee68d85df22e554040cdb4be100f33873ac6051387baf6a8f6ce82272340ff1c"}, - "conv_case": {:hex, :conv_case, "0.2.3", "c1455c27d3c1ffcdd5f17f1e91f40b8a0bc0a337805a6e8302f441af17118ed8", [:mix], [], "hexpm", "88f29a3d97d1742f9865f7e394ed3da011abb7c5e8cc104e676fdef6270d4b4a"}, - "db_connection": {:hex, :db_connection, "2.7.0", "b99faa9291bb09892c7da373bb82cba59aefa9b36300f6145c5f201c7adf48ec", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "dcf08f31b2701f857dfc787fbad78223d61a32204f217f15e881dd93e4bdd3ff"}, - "decimal": {:hex, :decimal, "2.3.0", "3ad6255aa77b4a3c4f818171b12d237500e63525c2fd056699967a3e7ea20f62", [:mix], [], "hexpm", "a4d66355cb29cb47c3cf30e71329e58361cfcb37c34235ef3bf1d7bf3773aeac"}, - "dns_cluster": {:hex, :dns_cluster, "0.1.3", "0bc20a2c88ed6cc494f2964075c359f8c2d00e1bf25518a6a6c7fd277c9b0c66", [:mix], [], "hexpm", "46cb7c4a1b3e52c7ad4cbe33ca5079fbde4840dedeafca2baf77996c2da1bc33"}, - "ecto": {:hex, :ecto, "3.12.5", "4a312960ce612e17337e7cefcf9be45b95a3be6b36b6f94dfb3d8c361d631866", [:mix], [{:decimal, "~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "6eb18e80bef8bb57e17f5a7f068a1719fbda384d40fc37acb8eb8aeca493b6ea"}, - "ecto_sql": {:hex, :ecto_sql, "3.12.1", "c0d0d60e85d9ff4631f12bafa454bc392ce8b9ec83531a412c12a0d415a3a4d0", [:mix], [{:db_connection, "~> 2.4.1 or ~> 2.5", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.12", [hex: :ecto, repo: "hexpm", optional: false]}, {:myxql, "~> 0.7", [hex: :myxql, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.19 or ~> 1.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:tds, "~> 2.1.1 or ~> 2.2", [hex: :tds, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.0 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "aff5b958a899762c5f09028c847569f7dfb9cc9d63bdb8133bff8a5546de6bf5"}, - "ets": {:hex, :ets, "0.9.0", "79c6a6c205436780486f72d84230c6cba2f8a9920456750ddd1e47389107d5fd", [:mix], [], "hexpm", "2861fdfb04bcaeff370f1a5904eec864f0a56dcfebe5921ea9aadf2a481c822b"}, - "ex2ms": {:hex, :ex2ms, "1.7.0", "45b9f523d0b777667ded60070d82d871a37e294f0b6c5b8eca86771f00f82ee1", [:mix], [], "hexpm", "2589eee51f81f1b1caa6d08c990b1ad409215fe6f64c73f73c67d36ed10be827"}, - "finch": {:hex, :finch, "0.19.0", "c644641491ea854fc5c1bbaef36bfc764e3f08e7185e1f084e35e0672241b76d", [:mix], [{:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:mint, "~> 1.6.2 or ~> 1.7", [hex: :mint, repo: "hexpm", optional: false]}, {:nimble_options, "~> 0.4 or ~> 1.0", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:nimble_pool, "~> 1.1", [hex: :nimble_pool, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "fc5324ce209125d1e2fa0fcd2634601c52a787aff1cd33ee833664a5af4ea2b6"}, - "glob_ex": {:hex, :glob_ex, "0.1.11", "cb50d3f1ef53f6ca04d6252c7fde09fd7a1cf63387714fe96f340a1349e62c93", [:mix], [], "hexpm", "342729363056e3145e61766b416769984c329e4378f1d558b63e341020525de4"}, - "hackney": {:hex, :hackney, "1.20.1", "8d97aec62ddddd757d128bfd1df6c5861093419f8f7a4223823537bad5d064e2", [:rebar3], [{:certifi, "~> 2.12.0", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "~> 6.1.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "~> 1.0.0", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "~> 1.1", [hex: :mimerl, repo: "hexpm", optional: false]}, {:parse_trans, "3.4.1", [hex: :parse_trans, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "~> 1.1.0", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}, {:unicode_util_compat, "~> 0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "fe9094e5f1a2a2c0a7d10918fee36bfec0ec2a979994cff8cfe8058cd9af38e3"}, - "hpax": {:hex, :hpax, "1.0.1", "c857057f89e8bd71d97d9042e009df2a42705d6d690d54eca84c8b29af0787b0", [:mix], [], "hexpm", "4e2d5a4f76ae1e3048f35ae7adb1641c36265510a2d4638157fbcb53dda38445"}, - "idna": {:hex, :idna, "6.1.1", "8a63070e9f7d0c62eb9d9fcb360a7de382448200fbbd1b106cc96d3d8099df8d", [:rebar3], [{:unicode_util_compat, "~> 0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "92376eb7894412ed19ac475e4a86f7b413c1b9fbb5bd16dccd57934157944cea"}, - "igniter": {:hex, :igniter, "0.4.8", "6d1bf4934952ac3eb20f6cbac0d5cd6d8012e42e3de20ad794703556c14cfa08", [:mix], [{:glob_ex, "~> 0.1.7", [hex: :glob_ex, repo: "hexpm", optional: false]}, {:jason, "~> 1.4", [hex: :jason, repo: "hexpm", optional: false]}, {:rewrite, ">= 1.1.1 and < 2.0.0-0", [hex: :rewrite, repo: "hexpm", optional: false]}, {:sourceror, "~> 1.4", [hex: :sourceror, repo: "hexpm", optional: false]}, {:spitfire, ">= 0.1.3 and < 1.0.0-0", [hex: :spitfire, repo: "hexpm", optional: false]}], "hexpm", "f9dd06f971fa053c6b0d9f8263b625f619a0fd3645d6a8cd6170935055a8f0df"}, - "inflex": {:hex, :inflex, "2.1.0", "a365cf0821a9dacb65067abd95008ca1b0bb7dcdd85ae59965deef2aa062924c", [:mix], [], "hexpm", "14c17d05db4ee9b6d319b0bff1bdf22aa389a25398d1952c7a0b5f3d93162dd8"}, - "iterex": {:hex, :iterex, "0.1.2", "58f9b9b9a22a55cbfc7b5234a9c9c63eaac26d276b3db80936c0e1c60355a5a6", [:mix], [], "hexpm", "2e103b8bcc81757a9af121f6dc0df312c9a17220f302b1193ef720460d03029d"}, - "jason": {:hex, :jason, "1.4.4", "b9226785a9aa77b6857ca22832cffa5d5011a667207eb2a0ad56adb5db443b8a", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "c5eb0cab91f094599f94d55bc63409236a8ec69a21a67814529e8d5f6cc90b3b"}, - "json_xema": {:hex, :json_xema, "0.6.4", "a70ec373f54279369a0bd7c80a8ab2421fb317a68abdf2d9be71b34dbdc1ec78", [:mix], [{:conv_case, "~> 0.2", [hex: :conv_case, repo: "hexpm", optional: false]}, {:xema, "~> 0.16", [hex: :xema, repo: "hexpm", optional: false]}], "hexpm", "ee91cfd6720f8ad13245fa2c438e862e6d8f46e2d700c714d72d259dcac7dfbc"}, - "libgraph": {:hex, :libgraph, "0.16.0", "3936f3eca6ef826e08880230f806bfea13193e49bf153f93edcf0239d4fd1d07", [:mix], [], "hexpm", "41ca92240e8a4138c30a7e06466acc709b0cbb795c643e9e17174a178982d6bf"}, - "metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], [], "hexpm", "69b09adddc4f74a40716ae54d140f93beb0fb8978d8636eaded0c31b6f099f16"}, - "mime": {:hex, :mime, "2.0.6", "8f18486773d9b15f95f4f4f1e39b710045fa1de891fada4516559967276e4dc2", [:mix], [], "hexpm", "c9945363a6b26d747389aac3643f8e0e09d30499a138ad64fe8fd1d13d9b153e"}, - "mimerl": {:hex, :mimerl, "1.3.0", "d0cd9fc04b9061f82490f6581e0128379830e78535e017f7780f37fea7545726", [:rebar3], [], "hexpm", "a1e15a50d1887217de95f0b9b0793e32853f7c258a5cd227650889b38839fe9d"}, - "mint": {:hex, :mint, "1.6.2", "af6d97a4051eee4f05b5500671d47c3a67dac7386045d87a904126fd4bbcea2e", [:mix], [{:castore, "~> 0.1.0 or ~> 1.0", [hex: :castore, repo: "hexpm", optional: true]}, {:hpax, "~> 0.1.1 or ~> 0.2.0 or ~> 1.0", [hex: :hpax, repo: "hexpm", optional: false]}], "hexpm", "5ee441dffc1892f1ae59127f74afe8fd82fda6587794278d924e4d90ea3d63f9"}, - "nimble_options": {:hex, :nimble_options, "1.1.1", "e3a492d54d85fc3fd7c5baf411d9d2852922f66e69476317787a7b2bb000a61b", [:mix], [], "hexpm", "821b2470ca9442c4b6984882fe9bb0389371b8ddec4d45a9504f00a66f650b44"}, - "nimble_ownership": {:hex, :nimble_ownership, "1.0.1", "f69fae0cdd451b1614364013544e66e4f5d25f36a2056a9698b793305c5aa3a6", [:mix], [], "hexpm", "3825e461025464f519f3f3e4a1f9b68c47dc151369611629ad08b636b73bb22d"}, - "nimble_pool": {:hex, :nimble_pool, "1.1.0", "bf9c29fbdcba3564a8b800d1eeb5a3c58f36e1e11d7b7fb2e084a643f645f06b", [:mix], [], "hexpm", "af2e4e6b34197db81f7aad230c1118eac993acc0dae6bc83bac0126d4ae0813a"}, - "owl": {:hex, :owl, "0.12.0", "0c4b48f90797a7f5f09ebd67ba7ebdc20761c3ec9c7928dfcafcb6d3c2d25c99", [:mix], [{:ucwidth, "~> 0.2", [hex: :ucwidth, repo: "hexpm", optional: true]}], "hexpm", "241d85ae62824dd72f9b2e4a5ba4e69ebb9960089a3c68ce6c1ddf2073db3c15"}, - "parse_trans": {:hex, :parse_trans, "3.4.1", "6e6aa8167cb44cc8f39441d05193be6e6f4e7c2946cb2759f015f8c56b76e5ff", [:rebar3], [], "hexpm", "620a406ce75dada827b82e453c19cf06776be266f5a67cff34e1ef2cbb60e49a"}, - "phoenix": {:hex, :phoenix, "1.7.18", "5310c21443514be44ed93c422e15870aef254cf1b3619e4f91538e7529d2b2e4", [:mix], [{:castore, ">= 0.0.0", [hex: :castore, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 2.1", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}, {:phoenix_template, "~> 1.0", [hex: :phoenix_template, repo: "hexpm", optional: false]}, {:phoenix_view, "~> 2.0", [hex: :phoenix_view, repo: "hexpm", optional: true]}, {:plug, "~> 1.14", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 2.7", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:plug_crypto, "~> 1.2 or ~> 2.0", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}, {:websock_adapter, "~> 0.5.3", [hex: :websock_adapter, repo: "hexpm", optional: false]}], "hexpm", "1797fcc82108442a66f2c77a643a62980f342bfeb63d6c9a515ab8294870004e"}, - "phoenix_ecto": {:hex, :phoenix_ecto, "4.6.3", "f686701b0499a07f2e3b122d84d52ff8a31f5def386e03706c916f6feddf69ef", [:mix], [{:ecto, "~> 3.5", [hex: :ecto, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 2.14.2 or ~> 3.0 or ~> 4.1", [hex: :phoenix_html, repo: "hexpm", optional: true]}, {:plug, "~> 1.9", [hex: :plug, repo: "hexpm", optional: false]}, {:postgrex, "~> 0.16 or ~> 1.0", [hex: :postgrex, repo: "hexpm", optional: true]}], "hexpm", "909502956916a657a197f94cc1206d9a65247538de8a5e186f7537c895d95764"}, - "phoenix_pubsub": {:hex, :phoenix_pubsub, "2.1.3", "3168d78ba41835aecad272d5e8cd51aa87a7ac9eb836eabc42f6e57538e3731d", [:mix], [], "hexpm", "bba06bc1dcfd8cb086759f0edc94a8ba2bc8896d5331a1e2c2902bf8e36ee502"}, - "phoenix_template": {:hex, :phoenix_template, "1.0.4", "e2092c132f3b5e5b2d49c96695342eb36d0ed514c5b252a77048d5969330d639", [:mix], [{:phoenix_html, "~> 2.14.2 or ~> 3.0 or ~> 4.0", [hex: :phoenix_html, repo: "hexpm", optional: true]}], "hexpm", "2c0c81f0e5c6753faf5cca2f229c9709919aba34fab866d3bc05060c9c444206"}, - "plug": {:hex, :plug, "1.16.1", "40c74619c12f82736d2214557dedec2e9762029b2438d6d175c5074c933edc9d", [:mix], [{:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.1.1 or ~> 1.2 or ~> 2.0", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.3 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "a13ff6b9006b03d7e33874945b2755253841b238c34071ed85b0e86057f8cddc"}, - "plug_crypto": {:hex, :plug_crypto, "2.1.0", "f44309c2b06d249c27c8d3f65cfe08158ade08418cf540fd4f72d4d6863abb7b", [:mix], [], "hexpm", "131216a4b030b8f8ce0f26038bc4421ae60e4bb95c5cf5395e1421437824c4fa"}, - "postgrex": {:hex, :postgrex, "0.19.3", "a0bda6e3bc75ec07fca5b0a89bffd242ca209a4822a9533e7d3e84ee80707e19", [:mix], [{:db_connection, "~> 2.1", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.5 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:table, "~> 0.1.0", [hex: :table, repo: "hexpm", optional: true]}], "hexpm", "d31c28053655b78f47f948c85bb1cf86a9c1f8ead346ba1aa0d0df017fa05b61"}, - "protobuf": {:hex, :protobuf, "0.13.0", "7a9d9aeb039f68a81717eb2efd6928fdf44f03d2c0dfdcedc7b560f5f5aae93d", [:mix], [{:jason, "~> 1.2", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm", "21092a223e3c6c144c1a291ab082a7ead32821ba77073b72c68515aa51fef570"}, - "reactor": {:hex, :reactor, "0.10.2", "a9150cbada58e5331c5250c51c6a8c2d7c4d337919fc71c7dc188a7ae5b6de89", [:mix], [{:igniter, "~> 0.2", [hex: :igniter, repo: "hexpm", optional: false]}, {:iterex, "~> 0.1", [hex: :iterex, repo: "hexpm", optional: false]}, {:libgraph, "~> 0.16", [hex: :libgraph, repo: "hexpm", optional: false]}, {:spark, "~> 2.0", [hex: :spark, repo: "hexpm", optional: false]}, {:splode, "~> 0.2", [hex: :splode, repo: "hexpm", optional: false]}, {:telemetry, "~> 1.2", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "5c46e71153f540b95e1a240365fc534daead9d19abe0d46eb819b7d715663484"}, - "recon": {:hex, :recon, "2.5.6", "9052588e83bfedfd9b72e1034532aee2a5369d9d9343b61aeb7fbce761010741", [:mix, :rebar3], [], "hexpm", "96c6799792d735cc0f0fd0f86267e9d351e63339cbe03df9d162010cefc26bb0"}, - "recon_ex": {:git, "https://github.com/tatsuya6502/recon_ex.git", "0ce4c5da777937a5bb57d3e68b9afcb9877c1c3b", [ref: "0ce4c5d"]}, - "req": {:hex, :req, "0.5.8", "50d8d65279d6e343a5e46980ac2a70e97136182950833a1968b371e753f6a662", [:mix], [{:brotli, "~> 0.3.1", [hex: :brotli, repo: "hexpm", optional: true]}, {:ezstd, "~> 1.0", [hex: :ezstd, repo: "hexpm", optional: true]}, {:finch, "~> 0.17", [hex: :finch, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}, {:mime, "~> 2.0.6 or ~> 2.1", [hex: :mime, repo: "hexpm", optional: false]}, {:nimble_csv, "~> 1.0", [hex: :nimble_csv, repo: "hexpm", optional: true]}, {:plug, "~> 1.0", [hex: :plug, repo: "hexpm", optional: true]}], "hexpm", "d7fc5898a566477e174f26887821a3c5082b243885520ee4b45555f5d53f40ef"}, - "retry": {:hex, :retry, "0.18.0", "dc58ebe22c95aa00bc2459f9e0c5400e6005541cf8539925af0aa027dc860543", [:mix], [], "hexpm", "9483959cc7bf69c9e576d9dfb2b678b71c045d3e6f39ab7c9aa1489df4492d73"}, - "rewrite": {:hex, :rewrite, "1.1.1", "0e6674eb5f8cb11aabe5ad6207151b4156bf173aa9b43133a68f8cc882364570", [:mix], [{:glob_ex, "~> 0.1", [hex: :glob_ex, repo: "hexpm", optional: false]}, {:sourceror, "~> 1.0", [hex: :sourceror, repo: "hexpm", optional: false]}, {:text_diff, "~> 0.1", [hex: :text_diff, repo: "hexpm", optional: false]}], "hexpm", "fcd688b3ca543c3a1f1f4615ccc054ec37cfcde91133a27a683ec09b35ae1496"}, - "sentry": {:hex, :sentry, "10.8.1", "aa45309785e1521416225adb16e0b4d8b957578804527f3c7babb6fefbc5e456", [:mix], [{:hackney, "~> 1.8", [hex: :hackney, repo: "hexpm", optional: true]}, {:jason, "~> 1.1", [hex: :jason, repo: "hexpm", optional: true]}, {:nimble_options, "~> 1.0", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:nimble_ownership, "~> 0.3.0 or ~> 1.0", [hex: :nimble_ownership, repo: "hexpm", optional: false]}, {:phoenix, "~> 1.6", [hex: :phoenix, repo: "hexpm", optional: true]}, {:phoenix_live_view, "~> 0.20 or ~> 1.0", [hex: :phoenix_live_view, repo: "hexpm", optional: true]}, {:plug, "~> 1.6", [hex: :plug, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: true]}], "hexpm", "495b3cdadad90ba72eef973aa3dec39b3b8b2a362fe87e2f4ef32133ac3b4097"}, - "sourceror": {:hex, :sourceror, "1.7.1", "599d78f4cc2be7d55c9c4fd0a8d772fd0478e3a50e726697c20d13d02aa056d4", [:mix], [], "hexpm", "cd6f268fe29fa00afbc535e215158680a0662b357dc784646d7dff28ac65a0fc"}, - "spark": {:hex, :spark, "2.2.35", "1c0bb30f340151eca24164885935de39e6ada4010555f444c813d0488990f8f3", [:mix], [{:igniter, ">= 0.3.64 and < 1.0.0-0", [hex: :igniter, repo: "hexpm", optional: false]}, {:jason, "~> 1.4", [hex: :jason, repo: "hexpm", optional: false]}, {:sourceror, "~> 1.2", [hex: :sourceror, repo: "hexpm", optional: false]}], "hexpm", "f242d6385c287389034a0e146d8f025b5c9ab777f1ae5cf0fdfc9209db6ae748"}, - "spitfire": {:hex, :spitfire, "0.1.3", "7ea0f544005dfbe48e615ed90250c9a271bfe126914012023fd5e4b6b82b7ec7", [:mix], [], "hexpm", "d53b5107bcff526a05c5bb54c95e77b36834550affd5830c9f58760e8c543657"}, - "splode": {:hex, :splode, "0.2.7", "ed042fa9bd8fe7b66dd0a0faabdb97352058420d90cd1c7c1537f609deb7ef6d", [:mix], [], "hexpm", "267f1f51d5a5ac988cda0649498294844988c5086916fed5a8aff297d69a2059"}, - "ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.7", "354c321cf377240c7b8716899e182ce4890c5938111a1296add3ec74cf1715df", [:make, :mix, :rebar3], [], "hexpm", "fe4c190e8f37401d30167c8c405eda19469f34577987c76dde613e838bbc67f8"}, - "stream_data": {:hex, :stream_data, "1.1.2", "05499eaec0443349ff877aaabc6e194e82bda6799b9ce6aaa1aadac15a9fdb4d", [:mix], [], "hexpm", "129558d2c77cbc1eb2f4747acbbea79e181a5da51108457000020a906813a1a9"}, - "stripity_stripe": {:hex, :stripity_stripe, "3.2.0", "07c27f5f2ac87006945b5c997b99d1210e009e380ea78d339d025b11c9c745f5", [:mix], [{:hackney, "~> 1.18", [hex: :hackney, repo: "hexpm", optional: false]}, {:jason, "~> 1.1", [hex: :jason, repo: "hexpm", optional: false]}, {:plug, "~> 1.14", [hex: :plug, repo: "hexpm", optional: true]}, {:telemetry, "~> 1.1", [hex: :telemetry, repo: "hexpm", optional: false]}, {:uri_query, "~> 0.2.0", [hex: :uri_query, repo: "hexpm", optional: false]}], "hexpm", "f797936a9e9538370bae7dc73d73eafd7e44ecdc95b71c88492c43f6df094cb0"}, - "telemetry": {:hex, :telemetry, "1.3.0", "fedebbae410d715cf8e7062c96a1ef32ec22e764197f70cda73d82778d61e7a2", [:rebar3], [], "hexpm", "7015fc8919dbe63764f4b4b87a95b7c0996bd539e0d499be6ec9d7f3875b79e6"}, - "telemetry_metrics": {:hex, :telemetry_metrics, "1.0.0", "29f5f84991ca98b8eb02fc208b2e6de7c95f8bb2294ef244a176675adc7775df", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "f23713b3847286a534e005126d4c959ebcca68ae9582118ce436b521d1d47d5d"}, - "telemetry_poller": {:hex, :telemetry_poller, "1.1.0", "58fa7c216257291caaf8d05678c8d01bd45f4bdbc1286838a28c4bb62ef32999", [:rebar3], [{:telemetry, "~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "9eb9d9cbfd81cbd7cdd24682f8711b6e2b691289a0de6826e58452f28c103c8f"}, - "text_diff": {:hex, :text_diff, "0.1.0", "1caf3175e11a53a9a139bc9339bd607c47b9e376b073d4571c031913317fecaa", [:mix], [], "hexpm", "d1ffaaecab338e49357b6daa82e435f877e0649041ace7755583a0ea3362dbd7"}, - "thousand_island": {:hex, :thousand_island, "1.3.7", "1da7598c0f4f5f50562c097a3f8af308ded48cd35139f0e6f17d9443e4d0c9c5", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "0139335079953de41d381a6134d8b618d53d084f558c734f2662d1a72818dd12"}, - "unicode_util_compat": {:hex, :unicode_util_compat, "0.7.0", "bc84380c9ab48177092f43ac89e4dfa2c6d62b40b8bd132b1059ecc7232f9a78", [:rebar3], [], "hexpm", "25eee6d67df61960cf6a794239566599b09e17e668d3700247bc498638152521"}, - "uri_query": {:hex, :uri_query, "0.2.0", "0f5e0f7ea6d9e6a7fb4929a81df9ecd756e3c71bdee5c9bc14e57d90069a82f7", [:mix], [], "hexpm", "e99f50a6af7c6643dff948db152a6a420bfe446aaec7f0924cfcdb710c175e63"}, - "websock": {:hex, :websock, "0.5.3", "2f69a6ebe810328555b6fe5c831a851f485e303a7c8ce6c5f675abeb20ebdadc", [:mix], [], "hexpm", "6105453d7fac22c712ad66fab1d45abdf049868f253cf719b625151460b8b453"}, - "websock_adapter": {:hex, :websock_adapter, "0.5.8", "3b97dc94e407e2d1fc666b2fb9acf6be81a1798a2602294aac000260a7c4a47d", [:mix], [{:bandit, ">= 0.6.0", [hex: :bandit, repo: "hexpm", optional: true]}, {:plug, "~> 1.14", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 2.6", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:websock, "~> 0.5", [hex: :websock, repo: "hexpm", optional: false]}], "hexpm", "315b9a1865552212b5f35140ad194e67ce31af45bcee443d4ecb96b5fd3f3782"}, - "websockex": {:hex, :websockex, "0.4.3", "92b7905769c79c6480c02daacaca2ddd49de936d912976a4d3c923723b647bf0", [:mix], [], "hexpm", "95f2e7072b85a3a4cc385602d42115b73ce0b74a9121d0d6dbbf557645ac53e4"}, - "xema": {:hex, :xema, "0.17.4", "e958baaf1f8238414c0646a6946a2fa8812673d14771aefc12af182b97d20665", [:mix], [{:conv_case, "~> 0.2.2", [hex: :conv_case, repo: "hexpm", optional: false]}, {:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "faf638de7c424326f089475db8077c86506af971537eb2097e06124c5e0e4240"}, -} diff --git a/server-old/priv/repo/migrations/.formatter.exs b/server-old/priv/repo/migrations/.formatter.exs deleted file mode 100644 index 49f9151ed2..0000000000 --- a/server-old/priv/repo/migrations/.formatter.exs +++ /dev/null @@ -1,4 +0,0 @@ -[ - import_deps: [:ecto_sql], - inputs: ["*.exs"] -] diff --git a/server-old/priv/repo/seeds.exs b/server-old/priv/repo/seeds.exs deleted file mode 100644 index ecbcea6010..0000000000 --- a/server-old/priv/repo/seeds.exs +++ /dev/null @@ -1,11 +0,0 @@ -# Script for populating the database. You can run it as: -# -# mix run priv/repo/seeds.exs -# -# Inside the script, you can read and write to any of your -# repositories directly: -# -# Hypr.Repo.insert!(%Hypr.SomeSchema{}) -# -# We recommend using the bang functions (`insert!`, `update!` -# and so on) as they will fail if something goes wrong. diff --git a/server-old/priv/static/favicon.ico b/server-old/priv/static/favicon.ico deleted file mode 100644 index 7f372bfc21cdd8cb47585339d5fa4d9dd424402f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 152 zcmeAS@N?(olHy`uVBq!ia0vp^4j|0I1|(Ny7TyC=@t!V@Ar*{oFEH`~d50E!_s``s q?{G*w(7?#d#v@^nKnY_HKaYb01EZMZjMqTJ89ZJ6T-G@yGywoKK_h|y diff --git a/server-old/priv/static/robots.txt b/server-old/priv/static/robots.txt deleted file mode 100644 index 26e06b5f19..0000000000 --- a/server-old/priv/static/robots.txt +++ /dev/null @@ -1,5 +0,0 @@ -# See https://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file -# -# To ban all spiders from the entire site uncomment the next two lines: -# User-agent: * -# Disallow: / diff --git a/server-old/rel/env.sh.eex b/server-old/rel/env.sh.eex deleted file mode 100755 index efeb7ffa27..0000000000 --- a/server-old/rel/env.sh.eex +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/sh - -# configure node for distributed erlang with IPV6 support -export ERL_AFLAGS="-proto_dist inet6_tcp" -export ECTO_IPV6="true" -export DNS_CLUSTER_QUERY="${FLY_APP_NAME}.internal" -export RELEASE_DISTRIBUTION="name" -export RELEASE_NODE="${FLY_APP_NAME}-${FLY_IMAGE_REF##*-}@${FLY_PRIVATE_IP}" - -# Uncomment to send crash dumps to stderr -# This can be useful for debugging, but may log sensitive information -# export ERL_CRASH_DUMP=/dev/stderr -# export ERL_CRASH_DUMP_BYTES=4096 diff --git a/server-old/rel/overlays/bin/migrate b/server-old/rel/overlays/bin/migrate deleted file mode 100755 index cd09bb1356..0000000000 --- a/server-old/rel/overlays/bin/migrate +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh -set -eu - -cd -P -- "$(dirname -- "$0")" -exec ./hypr eval Hypr.Release.migrate diff --git a/server-old/rel/overlays/bin/migrate.bat b/server-old/rel/overlays/bin/migrate.bat deleted file mode 100755 index 4815cec932..0000000000 --- a/server-old/rel/overlays/bin/migrate.bat +++ /dev/null @@ -1 +0,0 @@ -call "%~dp0\hypr" eval Hypr.Release.migrate diff --git a/server-old/rel/overlays/bin/server b/server-old/rel/overlays/bin/server deleted file mode 100755 index cf97e0d04b..0000000000 --- a/server-old/rel/overlays/bin/server +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh -set -eu - -cd -P -- "$(dirname -- "$0")" -PHX_SERVER=true exec ./hypr start diff --git a/server-old/rel/overlays/bin/server.bat b/server-old/rel/overlays/bin/server.bat deleted file mode 100755 index 34b5b8b8f7..0000000000 --- a/server-old/rel/overlays/bin/server.bat +++ /dev/null @@ -1,2 +0,0 @@ -set PHX_SERVER=true -call "%~dp0\hypr" start diff --git a/server-old/test/hypr_web/controllers/error_json_test.exs b/server-old/test/hypr_web/controllers/error_json_test.exs deleted file mode 100644 index 1c10632f2f..0000000000 --- a/server-old/test/hypr_web/controllers/error_json_test.exs +++ /dev/null @@ -1,12 +0,0 @@ -defmodule HyprWeb.ErrorJSONTest do - use HyprWeb.ConnCase, async: true - - test "renders 404" do - assert HyprWeb.ErrorJSON.render("404.json", %{}) == %{errors: %{detail: "Not Found"}} - end - - test "renders 500" do - assert HyprWeb.ErrorJSON.render("500.json", %{}) == - %{errors: %{detail: "Internal Server Error"}} - end -end diff --git a/server-old/test/support/conn_case.ex b/server-old/test/support/conn_case.ex deleted file mode 100644 index b183f3f257..0000000000 --- a/server-old/test/support/conn_case.ex +++ /dev/null @@ -1,38 +0,0 @@ -defmodule HyprWeb.ConnCase do - @moduledoc """ - This module defines the test case to be used by - tests that require setting up a connection. - - Such tests rely on `Phoenix.ConnTest` and also - import other functionality to make it easier - to build common data structures and query the data layer. - - Finally, if the test case interacts with the database, - we enable the SQL sandbox, so changes done to the database - are reverted at the end of every test. If you are using - PostgreSQL, you can even run database tests asynchronously - by setting `use HyprWeb.ConnCase, async: true`, although - this option is not recommended for other databases. - """ - - use ExUnit.CaseTemplate - - using do - quote do - # The default endpoint for testing - @endpoint HyprWeb.Endpoint - - use HyprWeb, :verified_routes - - # Import conveniences for testing with connections - import Plug.Conn - import Phoenix.ConnTest - import HyprWeb.ConnCase - end - end - - setup tags do - Hypr.DataCase.setup_sandbox(tags) - {:ok, conn: Phoenix.ConnTest.build_conn()} - end -end diff --git a/server-old/test/support/data_case.ex b/server-old/test/support/data_case.ex deleted file mode 100644 index ae43222f32..0000000000 --- a/server-old/test/support/data_case.ex +++ /dev/null @@ -1,58 +0,0 @@ -defmodule Hypr.DataCase do - @moduledoc """ - This module defines the setup for tests requiring - access to the application's data layer. - - You may define functions here to be used as helpers in - your tests. - - Finally, if the test case interacts with the database, - we enable the SQL sandbox, so changes done to the database - are reverted at the end of every test. If you are using - PostgreSQL, you can even run database tests asynchronously - by setting `use Hypr.DataCase, async: true`, although - this option is not recommended for other databases. - """ - - use ExUnit.CaseTemplate - - using do - quote do - alias Hypr.Repo - - import Ecto - import Ecto.Changeset - import Ecto.Query - import Hypr.DataCase - end - end - - setup tags do - Hypr.DataCase.setup_sandbox(tags) - :ok - end - - @doc """ - Sets up the sandbox based on the test tags. - """ - def setup_sandbox(tags) do - pid = Ecto.Adapters.SQL.Sandbox.start_owner!(Hypr.Repo, shared: not tags[:async]) - on_exit(fn -> Ecto.Adapters.SQL.Sandbox.stop_owner(pid) end) - end - - @doc """ - A helper that transforms changeset errors into a map of messages. - - assert {:error, changeset} = Accounts.create_user(%{password: "short"}) - assert "password is too short" in errors_on(changeset).password - assert %{password: ["password is too short"]} = errors_on(changeset) - - """ - def errors_on(changeset) do - Ecto.Changeset.traverse_errors(changeset, fn {message, opts} -> - Regex.replace(~r"%{(\w+)}", message, fn _, key -> - opts |> Keyword.get(String.to_existing_atom(key), key) |> to_string() - end) - end) - end -end diff --git a/server-old/test/test_helper.exs b/server-old/test/test_helper.exs deleted file mode 100644 index 7b0e22f0fe..0000000000 --- a/server-old/test/test_helper.exs +++ /dev/null @@ -1,2 +0,0 @@ -ExUnit.start() -Ecto.Adapters.SQL.Sandbox.mode(Hypr.Repo, :manual) From 266b7b1aca907ac3e50ebd6bbda774768466f13b Mon Sep 17 00:00:00 2001 From: yujonglee Date: Thu, 19 Dec 2024 17:42:50 +0900 Subject: [PATCH 08/13] fix database connection --- server/config/runtime.exs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/config/runtime.exs b/server/config/runtime.exs index e880241348..c78ade877c 100644 --- a/server/config/runtime.exs +++ b/server/config/runtime.exs @@ -31,10 +31,10 @@ if config_env() == :prod do maybe_ipv6 = if System.get_env("ECTO_IPV6") in ~w(true 1), do: [:inet6], else: [] config :hypr, Hypr.Repo, - # ssl: true, url: database_url, pool_size: String.to_integer(System.get_env("POOL_SIZE") || "10"), - socket_options: maybe_ipv6 + ssl: [cacerts: :public_key.cacerts_get()], + socket_options: [:inet6] # The secret key base is used to sign/encrypt cookies and other secrets. # A default value is used in config/dev.exs and config/test.exs but you From 63ebce08f5fc53e1fdada3a2b90ce7ec572ac33c Mon Sep 17 00:00:00 2001 From: yujonglee Date: Thu, 19 Dec 2024 17:57:34 +0900 Subject: [PATCH 09/13] deeplink callback, auth store, cloud crate update --- Cargo.lock | 132 ++++------------------------- apps/desktop/src-tauri/src/auth.rs | 34 ++++++++ apps/desktop/src-tauri/src/lib.rs | 33 +++++++- crates/cloud/Cargo.toml | 3 +- crates/cloud/src/lib.rs | 41 ++------- 5 files changed, 87 insertions(+), 156 deletions(-) create mode 100644 apps/desktop/src-tauri/src/auth.rs diff --git a/Cargo.lock b/Cargo.lock index 04cbd1ab96..3c80bb4bfb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -265,23 +265,12 @@ version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "20cd0e2e25ea8e5f7e9df04578dc6cf5c83577fd09b1a46aaf5c85e1c33f2a7e" dependencies = [ - "event-listener 5.3.1", + "event-listener", "event-listener-strategy", "futures-core", "pin-project-lite", ] -[[package]] -name = "async-channel" -version = "1.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81953c529336010edd6d8e358f886d9581267795c61b19475b71314bffa46d35" -dependencies = [ - "concurrent-queue", - "event-listener 2.5.3", - "futures-core", -] - [[package]] name = "async-channel" version = "2.3.1" @@ -343,7 +332,7 @@ version = "3.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ff6e472cdea888a4bd64f342f09b3f50e1886d32afe8df3d663c01140b811b18" dependencies = [ - "event-listener 5.3.1", + "event-listener", "event-listener-strategy", "pin-project-lite", ] @@ -354,14 +343,14 @@ version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "63255f1dc2381611000436537bbedfe83183faa303a5a0edaf191edef06526bb" dependencies = [ - "async-channel 2.3.1", + "async-channel", "async-io", "async-lock", "async-signal", "async-task", "blocking", "cfg-if 1.0.0", - "event-listener 5.3.1", + "event-listener", "futures-lite", "rustix", "tracing", @@ -451,17 +440,6 @@ version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" -[[package]] -name = "atomic_enum" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6227a8d6fdb862bcb100c4314d0d9579e5cd73fa6df31a2e6f6e1acd3c5f1207" -dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.109", -] - [[package]] name = "atty" version = "0.2.14" @@ -749,7 +727,7 @@ version = "1.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "703f41c54fc768e63e091340b424302bb1c29ef4aa0c7f10fe849dfb114d29ea" dependencies = [ - "async-channel 2.3.1", + "async-channel", "async-task", "futures-io", "futures-lite", @@ -1380,12 +1358,11 @@ name = "cloud" version = "0.1.0" dependencies = [ "anyhow", - "async-trait", "db", - "ezsockets", "proto", "reqwest 0.12.9", "tokio", + "tokio-tungstenite", "url", ] @@ -2553,20 +2530,6 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a3d8a32ae18130a3c84dd492d4215c3d913c3b07c6b63c2eb3eb7ff1101ab7bf" -[[package]] -name = "enfync" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ce8c1fbec15a38aced3838c4d7ea90a1403bd50364b5cfe8008e679df0c8dde" -dependencies = [ - "async-trait", - "futures", - "tokio", - "wasm-bindgen", - "wasm-bindgen-futures", - "wasmtimer", -] - [[package]] name = "enum-as-inner" version = "0.6.1" @@ -2669,12 +2632,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "event-listener" -version = "2.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0" - [[package]] name = "event-listener" version = "5.3.1" @@ -2692,36 +2649,10 @@ version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3c3e4e0dd3673c1139bf041f3008816d9cf2946bbfac2945c09e523b8d7b05b2" dependencies = [ - "event-listener 5.3.1", + "event-listener", "pin-project-lite", ] -[[package]] -name = "ezsockets" -version = "0.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42421679952f7cbcabe45cc527b3891ff2bc9d60c38995a4b70f27e5c43da811" -dependencies = [ - "async-channel 1.9.0", - "async-trait", - "atomic_enum", - "base64 0.21.7", - "cfg-if 1.0.0", - "enfync", - "futures", - "futures-util", - "getrandom 0.2.15", - "http 0.2.12", - "tokio", - "tokio-tungstenite", - "tokio-tungstenite-wasm", - "tracing", - "tungstenite", - "url", - "wasm-bindgen-futures", - "wasmtimer", -] - [[package]] name = "fancy-regex" version = "0.13.0" @@ -8130,7 +8061,7 @@ dependencies = [ "crc", "crossbeam-queue", "either", - "event-listener 5.3.1", + "event-listener", "futures-channel", "futures-core", "futures-intrusive", @@ -9523,9 +9454,9 @@ dependencies = [ [[package]] name = "tokio-tungstenite" -version = "0.20.1" +version = "0.26.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "212d5dcb2a1ce06d81107c3d0ffa3121fe974b73f068c8282cb1c32328113b6c" +checksum = "5c14b3e8ebea4eb2577de77903e6c008d9ac80b5aae1f9ae781c5229ae935a44" dependencies = [ "futures-util", "log", @@ -9533,24 +9464,6 @@ dependencies = [ "tungstenite", ] -[[package]] -name = "tokio-tungstenite-wasm" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ec8c7cf09b20184f946f114e3d8c0deca34368912c90100812861c14bb63b66" -dependencies = [ - "futures-channel", - "futures-util", - "http 0.2.12", - "httparse", - "js-sys", - "thiserror 1.0.69", - "tokio", - "tokio-tungstenite", - "wasm-bindgen", - "web-sys", -] - [[package]] name = "tokio-util" version = "0.7.13" @@ -9696,20 +9609,19 @@ checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" [[package]] name = "tungstenite" -version = "0.20.1" +version = "0.26.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e3dac10fd62eaf6617d3a904ae222845979aec67c615d1c842b4002c7666fb9" +checksum = "d4ab519cc9c1e57e6cab1087f262f9fc978a4e9d5f943b0e029567521d3525cb" dependencies = [ "byteorder", "bytes", "data-encoding", - "http 0.2.12", + "http 1.2.0", "httparse", "log", "rand 0.8.5", "sha1", - "thiserror 1.0.69", - "url", + "thiserror 2.0.7", "utf-8", ] @@ -10178,20 +10090,6 @@ dependencies = [ "web-sys", ] -[[package]] -name = "wasmtimer" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7ed9d8b15c7fb594d72bfb4b5a276f3d2029333cd93a932f376f5937f6f80ee" -dependencies = [ - "futures", - "js-sys", - "parking_lot 0.12.3", - "pin-utils", - "slab", - "wasm-bindgen", -] - [[package]] name = "wayland-backend" version = "0.3.7" @@ -11274,7 +11172,7 @@ dependencies = [ "blocking", "derivative", "enumflags2", - "event-listener 5.3.1", + "event-listener", "futures-core", "futures-sink", "futures-util", diff --git a/apps/desktop/src-tauri/src/auth.rs b/apps/desktop/src-tauri/src/auth.rs new file mode 100644 index 0000000000..8b6e29b1c4 --- /dev/null +++ b/apps/desktop/src-tauri/src/auth.rs @@ -0,0 +1,34 @@ +// https://github.com/CapSoftware/Cap/blob/8671050aaff780f658507579e7d1d75e7ee25d59/apps/desktop/src-tauri/src/auth.rs + +use serde::{Deserialize, Serialize}; +use specta::Type; + +use tauri::{AppHandle, Runtime}; +use tauri_plugin_store::StoreExt; + +#[derive(Debug, Serialize, Deserialize, Type)] +pub struct AuthStore { + pub token: String, +} + +impl AuthStore { + pub fn load(app: &AppHandle) -> Result, String> { + let Some(store) = app + .store("store") + .map(|s| s.get("auth")) + .map_err(|e| e.to_string())? + else { + return Ok(None); + }; + + serde_json::from_value(store).map_err(|e| e.to_string()) + } + + pub fn get(app: &AppHandle) -> Result, String> { + let Some(Some(store)) = app.get_store("store").map(|s| s.get("auth")) else { + return Ok(None); + }; + + serde_json::from_value(store).map_err(|e| e.to_string()) + } +} diff --git a/apps/desktop/src-tauri/src/lib.rs b/apps/desktop/src-tauri/src/lib.rs index 02755f692a..56e1e0dfe5 100644 --- a/apps/desktop/src-tauri/src/lib.rs +++ b/apps/desktop/src-tauri/src/lib.rs @@ -1,8 +1,11 @@ use cap_media::feeds::{AudioInputFeed, AudioInputSamplesSender}; -use tauri::{AppHandle, Manager}; use tokio::sync::RwLock; +use tauri::{AppHandle, Emitter, Manager}; +use tauri_plugin_deep_link::DeepLinkExt; + mod audio; +mod auth; mod commands; mod config; mod db; @@ -84,14 +87,36 @@ pub fn run() { ); } - builder = builder.plugin(tauri_plugin_deep_link::init()); + builder = builder.plugin(tauri_plugin_deep_link::init()).setup(|app| { + let app_handle = app.handle().clone(); + + app.deep_link().on_open_url(move |event| { + let urls = event.urls(); + let url = urls.first().unwrap(); + + if url.path() == "/auth" { + let query_pairs: std::collections::HashMap = url + .query_pairs() + .map(|(k, v)| (k.to_string(), v.to_string())) + .collect(); + + let local_data_dir = app_handle.path().app_local_data_dir().unwrap(); + let file_path = local_data_dir.join("api_key.txt"); + let key = query_pairs.get("key").unwrap().clone(); + + std::fs::write(&file_path, key).unwrap(); + let _ = app_handle.emit("auth", true); + } + }); + + Ok(()) + }); // https://v2.tauri.app/plugin/deep-linking/#registering-desktop-deep-links-at-runtime #[cfg(any(windows, target_os = "linux"))] { builder = builder.setup(|app| { { - use tauri_plugin_deep_link::DeepLinkExt; app.deep_link().register_all()?; } @@ -144,6 +169,8 @@ pub fn run() { .setup(move |app| { let app = app.handle().clone(); + if let Ok(Some(_auth)) = auth::AuthStore::load(&app) {} + app.manage(RwLock::new(App { handle: app.clone(), audio_input_tx, diff --git a/crates/cloud/Cargo.toml b/crates/cloud/Cargo.toml index 47cf6eda68..ce8eb18f2b 100644 --- a/crates/cloud/Cargo.toml +++ b/crates/cloud/Cargo.toml @@ -12,5 +12,4 @@ tokio = { workspace = true } url = "2.5.4" reqwest = { version = "0.12.9", features = ["json"] } -ezsockets = { version = "0.6.4", features = ["native_client"] } -async-trait = "0.1.83" +tokio-tungstenite = "0.26.0" diff --git a/crates/cloud/src/lib.rs b/crates/cloud/src/lib.rs index 712ea560e5..76b10094e8 100644 --- a/crates/cloud/src/lib.rs +++ b/crates/cloud/src/lib.rs @@ -1,6 +1,6 @@ use anyhow::Result; -use async_trait::async_trait; use tokio::sync::mpsc; +use tokio_tungstenite::tungstenite; use url::Url; use hypr_proto::protobuf::Message; @@ -33,34 +33,14 @@ struct WebsocketClient { output_sender: TranscribeOutputSender, } -#[async_trait] -impl ezsockets::ClientExt for WebsocketClient { - // https://docs.rs/ezsockets/latest/ezsockets/client/trait.ClientExt.html - type Call = (); - - async fn on_text(&mut self, _text: String) -> Result<(), ezsockets::Error> { - Ok(()) - } - - async fn on_binary(&mut self, bytes: Vec) -> Result<(), ezsockets::Error> { - let data = proto::TranscribeOutputChunk::parse_from_bytes(&bytes).unwrap(); - let _ = self.output_sender.send(data).await; - Ok(()) - } - - async fn on_call(&mut self, _call: Self::Call) -> Result<(), ezsockets::Error> { - Ok(()) - } -} - pub struct Client { config: ClientConfig, reqwest_client: reqwest::Client, - ws_client: Option>, } pub struct ClientConfig { base_url: Url, + auth_token: String, } impl Client { @@ -70,7 +50,6 @@ impl Client { Self { config, reqwest_client: client, - ws_client: None, } } @@ -96,17 +75,11 @@ impl Client { let (input_sender, mut input_receiver) = mpsc::channel::(100); let (output_sender, output_receiver) = mpsc::channel::(100); - let config = ezsockets::ClientConfig::new(self.ws_url().as_str()); - - let (handle, future) = - ezsockets::connect(|_client| WebsocketClient { output_sender }, config).await; + let request = + tungstenite::ClientRequestBuilder::new(self.ws_url().to_string().parse().unwrap()) + .with_header("x-hypr-token", &self.config.auth_token); - tokio::spawn(async move { - while let Some(input) = input_receiver.recv().await { - let _ = handle.binary(input.audio); - } - future.await.unwrap(); - }); + let (stream, response) = tokio_tungstenite::connect_async(request).await?; Ok(TranscribeHandler { input_sender, @@ -115,7 +88,6 @@ impl Client { } pub fn ws_disconnect(&mut self) -> Result<()> { - self.ws_client.take().unwrap().close(None)?; Ok(()) } @@ -139,6 +111,7 @@ mod tests { async fn test_simple() { let _ = Client::new(ClientConfig { base_url: Url::parse("http://localhost:8080").unwrap(), + auth_token: "".to_string(), }); } } From 91485b407a5a49ae06d57986cbc8db9ace5377a2 Mon Sep 17 00:00:00 2001 From: yujonglee Date: Fri, 20 Dec 2024 10:12:28 +0900 Subject: [PATCH 10/13] use vendored protoc --- crates/proto/Cargo.toml | 5 +++-- crates/proto/build.rs | 2 +- crates/proto/src/generated/v0.rs | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/crates/proto/Cargo.toml b/crates/proto/Cargo.toml index 4cf837173d..67b92ea969 100644 --- a/crates/proto/Cargo.toml +++ b/crates/proto/Cargo.toml @@ -4,9 +4,10 @@ version = "0.1.0" edition = "2021" [build-dependencies] -protobuf-codegen = "3.7.1" protobuf = "3.7.1" +protobuf-codegen = "3.7.1" +protoc-bin-vendored = "3.1.0" [dependencies] -protobuf = { version = "3.7.1", features = ["bytes"] } bytes = "1.9.0" +protobuf = { version = "3.7.1", features = ["bytes"] } diff --git a/crates/proto/build.rs b/crates/proto/build.rs index 3eba595fdb..fbdb9579e5 100644 --- a/crates/proto/build.rs +++ b/crates/proto/build.rs @@ -1,7 +1,6 @@ use protobuf::descriptor::field_descriptor_proto::Type; use protobuf::reflect::FieldDescriptor; use protobuf_codegen::{Codegen, Customize, CustomizeCallback}; - struct BytesConverter; impl CustomizeCallback for BytesConverter { @@ -18,6 +17,7 @@ fn main() { println!("cargo:rerun-if-changed=../../packages/proto/v0.proto"); Codegen::new() + .protoc_path(&protoc_bin_vendored::protoc_bin_path().unwrap()) .out_dir("src/generated") .include("../../packages/proto") .input("../../packages/proto/v0.proto") diff --git a/crates/proto/src/generated/v0.rs b/crates/proto/src/generated/v0.rs index 27510d2da5..9b1b4b6413 100644 --- a/crates/proto/src/generated/v0.rs +++ b/crates/proto/src/generated/v0.rs @@ -1,5 +1,5 @@ // This file is generated by rust-protobuf 3.7.1. Do not edit -// .proto file is parsed by protoc 25.2 +// .proto file is parsed by protoc 28.2 // @generated // https://github.com/rust-lang/rust-clippy/issues/702 From 20e6117d5f6aa64c55465d9f956b973eef21a5b3 Mon Sep 17 00:00:00 2001 From: yujonglee Date: Fri, 20 Dec 2024 10:12:50 +0900 Subject: [PATCH 11/13] update cloud --- Cargo.lock | 59 +++++++++++++++++++++++++++++ crates/cloud/Cargo.toml | 1 + crates/cloud/src/lib.rs | 82 +++++++++++++++++++++++++++-------------- 3 files changed, 114 insertions(+), 28 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3c80bb4bfb..64341f6c1c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1359,6 +1359,7 @@ version = "0.1.0" dependencies = [ "anyhow", "db", + "futures-util", "proto", "reqwest 0.12.9", "tokio", @@ -6405,6 +6406,7 @@ dependencies = [ "bytes", "protobuf", "protobuf-codegen", + "protoc-bin-vendored", ] [[package]] @@ -6459,6 +6461,63 @@ dependencies = [ "thiserror 1.0.69", ] +[[package]] +name = "protoc-bin-vendored" +version = "3.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd89a830d0eab2502c81a9b8226d446a52998bb78e5e33cb2637c0cdd6068d99" +dependencies = [ + "protoc-bin-vendored-linux-aarch_64", + "protoc-bin-vendored-linux-ppcle_64", + "protoc-bin-vendored-linux-x86_32", + "protoc-bin-vendored-linux-x86_64", + "protoc-bin-vendored-macos-aarch_64", + "protoc-bin-vendored-macos-x86_64", + "protoc-bin-vendored-win32", +] + +[[package]] +name = "protoc-bin-vendored-linux-aarch_64" +version = "3.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f563627339f1653ea1453dfbcb4398a7369b768925eb14499457aeaa45afe22c" + +[[package]] +name = "protoc-bin-vendored-linux-ppcle_64" +version = "3.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5025c949a02cd3b60c02501dd0f348c16e8fff464f2a7f27db8a9732c608b746" + +[[package]] +name = "protoc-bin-vendored-linux-x86_32" +version = "3.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c9500ce67d132c2f3b572504088712db715755eb9adf69d55641caa2cb68a07" + +[[package]] +name = "protoc-bin-vendored-linux-x86_64" +version = "3.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5462592380cefdc9f1f14635bcce70ba9c91c1c2464c7feb2ce564726614cc41" + +[[package]] +name = "protoc-bin-vendored-macos-aarch_64" +version = "3.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c637745681b68b4435484543667a37606c95ddacf15e917710801a0877506030" + +[[package]] +name = "protoc-bin-vendored-macos-x86_64" +version = "3.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38943f3c90319d522f94a6dfd4a134ba5e36148b9506d2d9723a82ebc57c8b55" + +[[package]] +name = "protoc-bin-vendored-win32" +version = "3.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dc55d7dec32ecaf61e0bd90b3d2392d721a28b95cfd23c3e176eccefbeab2f2" + [[package]] name = "ptr_meta" version = "0.1.4" diff --git a/crates/cloud/Cargo.toml b/crates/cloud/Cargo.toml index ce8eb18f2b..0d1a6dc347 100644 --- a/crates/cloud/Cargo.toml +++ b/crates/cloud/Cargo.toml @@ -13,3 +13,4 @@ tokio = { workspace = true } url = "2.5.4" reqwest = { version = "0.12.9", features = ["json"] } tokio-tungstenite = "0.26.0" +futures-util = "0.3.31" diff --git a/crates/cloud/src/lib.rs b/crates/cloud/src/lib.rs index 76b10094e8..52438883ac 100644 --- a/crates/cloud/src/lib.rs +++ b/crates/cloud/src/lib.rs @@ -1,9 +1,11 @@ use anyhow::Result; -use tokio::sync::mpsc; -use tokio_tungstenite::tungstenite; use url::Url; -use hypr_proto::protobuf::Message; +use futures_util::StreamExt; +use tokio::sync::mpsc; +use tokio_tungstenite::tungstenite::client::IntoClientRequest; + +// use hypr_proto::protobuf::Message; use hypr_proto::v0 as proto; pub type TranscribeInputSender = mpsc::Sender; @@ -16,6 +18,12 @@ pub struct TranscribeHandler { output_receiver: TranscribeOutputReceiver, } +// TODO: we are splitting, for concurrent usage & send/receive in multiple threads. +// it makes no sense if we combine this two. +// we should return 2 struct, I think. + +// TODO: periodical ping is needed. + impl TranscribeHandler { pub async fn tx(&self, value: proto::TranscribeInputChunk) -> Result<()> { self.input_sender @@ -29,10 +37,6 @@ impl TranscribeHandler { } } -struct WebsocketClient { - output_sender: TranscribeOutputSender, -} - pub struct Client { config: ClientConfig, reqwest_client: reqwest::Client, @@ -40,7 +44,12 @@ pub struct Client { pub struct ClientConfig { base_url: Url, - auth_token: String, + auth_token: Option, +} + +#[derive(Debug, PartialEq, Eq)] +pub enum AuthKind { + GoogleOAuth, } impl Client { @@ -53,33 +62,32 @@ impl Client { } } - fn enhance_url(&self) -> Url { - let mut url = self.config.base_url.clone(); - url.set_path("/enhance"); - url - } - - fn ws_url(&self) -> Url { - let mut url = self.config.base_url.clone(); - - if self.config.base_url.scheme() == "http" { - url.set_scheme("ws").unwrap(); - } else { - url.set_scheme("wss").unwrap(); + pub fn get_authentication_url(&self, kind: AuthKind) -> Url { + match kind { + AuthKind::GoogleOAuth => { + let mut url = self.config.base_url.clone(); + url.set_path("/auth/desktop/login/google"); + url + } } - - url } pub async fn ws_connect(&mut self) -> Result { + if self.config.auth_token.is_none() { + anyhow::bail!("No auth token provided"); + } + let (input_sender, mut input_receiver) = mpsc::channel::(100); let (output_sender, output_receiver) = mpsc::channel::(100); - let request = - tungstenite::ClientRequestBuilder::new(self.ws_url().to_string().parse().unwrap()) - .with_header("x-hypr-token", &self.config.auth_token); + let mut request = self.ws_url().to_string().into_client_request().unwrap(); + request.headers_mut().insert( + "x-hypr-token", + self.config.auth_token.clone().unwrap().parse().unwrap(), + ); - let (stream, response) = tokio_tungstenite::connect_async(request).await?; + let (ws_stream, _response) = tokio_tungstenite::connect_async(request).await?; + let (write, read) = ws_stream.split(); Ok(TranscribeHandler { input_sender, @@ -101,6 +109,24 @@ impl Client { Ok(()) } + + fn enhance_url(&self) -> Url { + let mut url = self.config.base_url.clone(); + url.set_path("/enhance"); + url + } + + fn ws_url(&self) -> Url { + let mut url = self.config.base_url.clone(); + + if self.config.base_url.scheme() == "http" { + url.set_scheme("ws").unwrap(); + } else { + url.set_scheme("wss").unwrap(); + } + + url + } } #[cfg(test)] @@ -111,7 +137,7 @@ mod tests { async fn test_simple() { let _ = Client::new(ClientConfig { base_url: Url::parse("http://localhost:8080").unwrap(), - auth_token: "".to_string(), + auth_token: Some("".to_string()), }); } } From 02c1434af61908020c00e91b5875be0bff3c2c69 Mon Sep 17 00:00:00 2001 From: yujonglee Date: Fri, 20 Dec 2024 10:43:00 +0900 Subject: [PATCH 12/13] wip --- apps/desktop/src-tauri/src/commands.rs | 35 ++++++++++++++------- apps/desktop/src-tauri/src/config.rs | 43 ++++++++++++++++++++------ apps/desktop/src-tauri/src/events.rs | 11 +++++-- apps/desktop/src-tauri/src/lib.rs | 39 ++++++++++++----------- apps/desktop/src/types/tauri.ts | 21 +++++-------- crates/cloud/src/lib.rs | 4 +-- 6 files changed, 97 insertions(+), 56 deletions(-) diff --git a/apps/desktop/src-tauri/src/commands.rs b/apps/desktop/src-tauri/src/commands.rs index c6f7bbc41d..f76ff52839 100644 --- a/apps/desktop/src-tauri/src/commands.rs +++ b/apps/desktop/src-tauri/src/commands.rs @@ -1,8 +1,8 @@ -use crate::{audio, config, permissions}; +use crate::{audio, auth::AuthStore, config::ConfigStore, permissions}; +use anyhow::Result; use cap_media::feeds::AudioInputFeed; use std::path::PathBuf; use tauri::{AppHandle, Manager}; -use tauri_plugin_store::StoreExt; #[tauri::command] #[specta::specta] @@ -68,6 +68,20 @@ pub fn stop_recording() { audio::AppSounds::StopRecording.play(); } +#[tauri::command] +#[specta::specta] +pub fn auth_url(app: AppHandle) -> String { + let config = hypr_cloud::ClientConfig { + base_url: "https://api.hypr.com".parse().unwrap(), + auth_token: None, + }; + + let client = hypr_cloud::Client::new(config); + client + .get_authentication_url(hypr_cloud::AuthKind::GoogleOAuth) + .to_string() +} + #[tauri::command] #[specta::specta] pub fn list_recordings(app: AppHandle) -> Result, String> { @@ -82,17 +96,16 @@ pub fn list_recordings(app: AppHandle) -> Result, String> #[tauri::command] #[specta::specta] -pub fn set_config(app: AppHandle, config: config::Config) { - let store = app.store("store.json").unwrap(); - store.set("config", serde_json::json!(config)); +pub fn is_authenticated(app: AppHandle) -> bool { + AuthStore::get(&app).is_ok() } -#[tauri::command] -#[specta::specta] -pub fn get_config(app: AppHandle) -> config::Config { - let store = app.store("store.json").unwrap(); - let value = store.get("config").unwrap(); - serde_json::from_value(value).unwrap() +pub enum AuthProvider { + Google, +} + +pub fn login(provider: AuthProvider) -> Result<(), String> { + Ok(()) } fn recordings_path(app: &AppHandle) -> PathBuf { diff --git a/apps/desktop/src-tauri/src/config.rs b/apps/desktop/src-tauri/src/config.rs index 2122b59932..cc91e6fe38 100644 --- a/apps/desktop/src-tauri/src/config.rs +++ b/apps/desktop/src-tauri/src/config.rs @@ -1,25 +1,50 @@ use serde::{Deserialize, Serialize}; use specta::Type; +use tauri::{AppHandle, Runtime}; +use tauri_plugin_store::StoreExt; + #[derive(Debug, Serialize, Deserialize, Type)] #[serde(untagged)] -pub enum Config { +pub enum ConfigStore { V0(ConfigV0), } -#[derive(Debug, Serialize, Deserialize, Type)] -pub struct ConfigV0 { - pub version: u8, - pub language: Language, - pub user_name: String, +impl ConfigStore { + pub fn load(app: &AppHandle) -> Result, String> { + let Some(store) = app + .store("store") + .map(|s: std::sync::Arc>| s.get("config")) + .map_err(|e| e.to_string())? + else { + return Ok(None); + }; + + serde_json::from_value(store).map_err(|e| e.to_string()) + } + + pub fn get(app: &AppHandle) -> Result, String> { + let Some(Some(store)) = app.get_store("store").map(|s| s.get("config")) else { + return Ok(None); + }; + + serde_json::from_value(store).map_err(|e| e.to_string()) + } } -impl Default for Config { +impl Default for ConfigStore { fn default() -> Self { Self::V0(ConfigV0::default()) } } +#[derive(Debug, Serialize, Deserialize, Type)] +pub struct ConfigV0 { + pub version: u8, + pub language: Language, + pub user_name: String, +} + impl Default for ConfigV0 { fn default() -> Self { Self { @@ -48,9 +73,9 @@ mod tests { #[test] fn test_default_config() { - let config = Config::default(); + let config = ConfigStore::default(); match config { - Config::V0(cfg_v0) => { + ConfigStore::V0(cfg_v0) => { assert_eq!(cfg_v0.version, 0); } } diff --git a/apps/desktop/src-tauri/src/events.rs b/apps/desktop/src-tauri/src/events.rs index 8d8e92e4f6..2972ffdca8 100644 --- a/apps/desktop/src-tauri/src/events.rs +++ b/apps/desktop/src-tauri/src/events.rs @@ -1,5 +1,12 @@ +use serde::{Deserialize, Serialize}; use specta::Type; use tauri_specta::Event; -#[derive(Type, Event)] -pub struct Transcript {} +#[derive(Debug, Clone, Serialize, Deserialize, Type, Event)] +pub struct Transcript; + +#[derive(Debug, Clone, Serialize, Deserialize, Type, Event)] +pub struct NotAuthenticated; + +#[derive(Debug, Clone, Serialize, Deserialize, Type, Event)] +pub struct JustAuthenticated; diff --git a/apps/desktop/src-tauri/src/lib.rs b/apps/desktop/src-tauri/src/lib.rs index 56e1e0dfe5..1a4720972a 100644 --- a/apps/desktop/src-tauri/src/lib.rs +++ b/apps/desktop/src-tauri/src/lib.rs @@ -1,8 +1,9 @@ use cap_media::feeds::{AudioInputFeed, AudioInputSamplesSender}; use tokio::sync::RwLock; -use tauri::{AppHandle, Emitter, Manager}; +use tauri::{AppHandle, Manager}; use tauri_plugin_deep_link::DeepLinkExt; +use tauri_specta::Event; mod audio; mod auth; @@ -28,8 +29,6 @@ pub struct App { pub fn run() { let specta_builder = tauri_specta::Builder::new() .commands(tauri_specta::collect_commands![ - commands::set_config, - commands::get_config, commands::list_audio_devices, commands::start_recording, commands::stop_recording, @@ -39,7 +38,11 @@ pub fn run() { commands::list_apple_events, permissions::open_permission_settings, ]) - .events(tauri_specta::collect_events![events::Transcript]) + .events(tauri_specta::collect_events![ + events::Transcript, + events::NotAuthenticated, + events::JustAuthenticated, + ]) .typ::() .typ::() .error_handling(tauri_specta::ErrorHandlingMode::Throw); @@ -105,7 +108,7 @@ pub fn run() { let key = query_pairs.get("key").unwrap().clone(); std::fs::write(&file_path, key).unwrap(); - let _ = app_handle.emit("auth", true); + let _ = events::JustAuthenticated.emit(&app_handle); } }); @@ -133,6 +136,19 @@ pub fn run() { let handler = specta_builder.invoke_handler(); move |invoke| handler(invoke) }) + .setup(move |app| { + let app = app.handle().clone(); + + if let Ok(Some(_auth)) = auth::AuthStore::load(&app) {} + + app.manage(RwLock::new(App { + handle: app.clone(), + audio_input_tx, + audio_input_feed: None, + })); + + Ok(()) + }) .setup(|app| { let salt_path = app.path().app_local_data_dir()?.join("salt.txt"); app.handle() @@ -166,19 +182,6 @@ pub fn run() { } Ok(()) }) - .setup(move |app| { - let app = app.handle().clone(); - - if let Ok(Some(_auth)) = auth::AuthStore::load(&app) {} - - app.manage(RwLock::new(App { - handle: app.clone(), - audio_input_tx, - audio_input_feed: None, - })); - - Ok(()) - }) .run(tauri::generate_context!()) .expect("error while running tauri application"); } diff --git a/apps/desktop/src/types/tauri.ts b/apps/desktop/src/types/tauri.ts index 5159462b0b..58c8b4a680 100644 --- a/apps/desktop/src/types/tauri.ts +++ b/apps/desktop/src/types/tauri.ts @@ -5,12 +5,6 @@ /** user-defined commands **/ export const commands = { - async setConfig(config: Config): Promise { - await TAURI_INVOKE("set_config", { config }); - }, - async getConfig(): Promise { - return await TAURI_INVOKE("get_config"); - }, async listAudioDevices(): Promise { return await TAURI_INVOKE("list_audio_devices"); }, @@ -40,8 +34,12 @@ export const commands = { /** user-defined events **/ export const events = __makeEvents__<{ + justAuthenticated: JustAuthenticated; + notAuthenticated: NotAuthenticated; transcript: Transcript; }>({ + justAuthenticated: "just-authenticated", + notAuthenticated: "not-authenticated", transcript: "transcript", }); @@ -50,24 +48,19 @@ export const events = __makeEvents__<{ /** user-defined types **/ export type Calendar = { title: string }; -export type Config = ConfigV0; -export type ConfigV0 = { - version: number; - language: Language; - user_name: string; -}; export type Event = { title: string; start_date: string; end_date: string }; export type EventFilter = { last_n_days: number | null; calendar_titles: string[]; }; -export type Language = "English" | "Korean"; +export type JustAuthenticated = null; +export type NotAuthenticated = null; export type OSPermission = | "screenRecording" | "camera" | "microphone" | "accessibility"; -export type Transcript = Record; +export type Transcript = null; /** tauri-specta globals **/ diff --git a/crates/cloud/src/lib.rs b/crates/cloud/src/lib.rs index 52438883ac..43277a6606 100644 --- a/crates/cloud/src/lib.rs +++ b/crates/cloud/src/lib.rs @@ -43,8 +43,8 @@ pub struct Client { } pub struct ClientConfig { - base_url: Url, - auth_token: Option, + pub base_url: Url, + pub auth_token: Option, } #[derive(Debug, PartialEq, Eq)] From 6f679f02657552cf4ce807440fe231ac12a9c3c5 Mon Sep 17 00:00:00 2001 From: yujonglee Date: Fri, 20 Dec 2024 12:42:14 +0900 Subject: [PATCH 13/13] add auth url opener in client side --- Cargo.lock | 78 +++++++++++++++++++ apps/desktop/package.json | 1 + apps/desktop/src-tauri/Cargo.toml | 1 + .../src-tauri/capabilities/default.json | 3 +- apps/desktop/src-tauri/src/commands.rs | 25 +++--- apps/desktop/src-tauri/src/lib.rs | 22 ++++-- apps/desktop/src/pages/Home.tsx | 11 ++- apps/desktop/src/types/tauri.ts | 3 + crates/cloud/src/lib.rs | 1 + pnpm-lock.yaml | 10 +++ 10 files changed, 132 insertions(+), 23 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 64341f6c1c..8d457df4c8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2189,6 +2189,7 @@ dependencies = [ "tauri-plugin-log", "tauri-plugin-notification", "tauri-plugin-positioner", + "tauri-plugin-shell", "tauri-plugin-single-instance", "tauri-plugin-sql", "tauri-plugin-store", @@ -4252,6 +4253,25 @@ version = "2.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ddc24109865250148c2e0f3d25d4f0f479571723792d3802153c60922a4fb708" +[[package]] +name = "is-docker" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "928bae27f42bc99b60d9ac7334e3a21d10ad8f1835a4e12ec3ec0464765ed1b3" +dependencies = [ + "once_cell", +] + +[[package]] +name = "is-wsl" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "173609498df190136aa7dea1a91db051746d339e18476eed5ca40521f02d7aa5" +dependencies = [ + "is-docker", + "once_cell", +] + [[package]] name = "iterator-sorted" version = "0.1.0" @@ -5765,6 +5785,17 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381" +[[package]] +name = "open" +version = "5.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ecd52f0b8d15c40ce4820aa251ed5de032e5d91fab27f7db2f40d42a8bdf69c" +dependencies = [ + "is-wsl", + "libc", + "pathdiff", +] + [[package]] name = "openssl" version = "0.10.68" @@ -5860,6 +5891,16 @@ dependencies = [ "ureq", ] +[[package]] +name = "os_pipe" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ffd2b0a5634335b135d5728d84c5e0fd726954b87111f7506a61c502280d982" +dependencies = [ + "libc", + "windows-sys 0.59.0", +] + [[package]] name = "pango" version = "0.18.3" @@ -5956,6 +5997,12 @@ version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" +[[package]] +name = "pathdiff" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df94ce210e5bc13cb6651479fa48d14f601d9858cfe0467f43ae157023b938d3" + [[package]] name = "pbkdf2" version = "0.12.2" @@ -7826,6 +7873,16 @@ dependencies = [ "digest", ] +[[package]] +name = "shared_child" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09fa9338aed9a1df411814a5b2252f7cd206c55ae9bf2fa763f8de84603aa60c" +dependencies = [ + "libc", + "windows-sys 0.59.0", +] + [[package]] name = "shlex" version = "0.1.1" @@ -9021,6 +9078,27 @@ dependencies = [ "thiserror 2.0.7", ] +[[package]] +name = "tauri-plugin-shell" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb2c50a63e60fb8925956cc5b7569f4b750ac197a4d39f13b8dd46ea8e2bad79" +dependencies = [ + "encoding_rs", + "log", + "open", + "os_pipe", + "regex", + "schemars", + "serde", + "serde_json", + "shared_child", + "tauri", + "tauri-plugin", + "thiserror 2.0.7", + "tokio", +] + [[package]] name = "tauri-plugin-single-instance" version = "2.2.0" diff --git a/apps/desktop/package.json b/apps/desktop/package.json index e8ba8224ed..85b033e838 100644 --- a/apps/desktop/package.json +++ b/apps/desktop/package.json @@ -27,6 +27,7 @@ "@tauri-apps/plugin-dialog": "^2.2.0", "@tauri-apps/plugin-fs": "^2.0.3", "@tauri-apps/plugin-log": "^2.2.0", + "@tauri-apps/plugin-shell": "^2.2.0", "@tauri-apps/plugin-updater": "^2.0.0", "@tiptap/extension-highlight": "^2.10.3", "@tiptap/extension-placeholder": "^2.10.3", diff --git a/apps/desktop/src-tauri/Cargo.toml b/apps/desktop/src-tauri/Cargo.toml index 77ab6fae19..aac747587b 100644 --- a/apps/desktop/src-tauri/Cargo.toml +++ b/apps/desktop/src-tauri/Cargo.toml @@ -57,3 +57,4 @@ flume = "0.11.1" objc = "0.2.7" cap-media = { workspace = true } tauri-plugin-stronghold = "2.2.0" +tauri-plugin-shell = "2.2.0" diff --git a/apps/desktop/src-tauri/capabilities/default.json b/apps/desktop/src-tauri/capabilities/default.json index b7df9f2ec0..93b86ca2cf 100644 --- a/apps/desktop/src-tauri/capabilities/default.json +++ b/apps/desktop/src-tauri/capabilities/default.json @@ -10,6 +10,7 @@ "sql:default", "sql:allow-execute", "store:default", - "stronghold:default" + "stronghold:default", + "shell:allow-open" ] } diff --git a/apps/desktop/src-tauri/src/commands.rs b/apps/desktop/src-tauri/src/commands.rs index f76ff52839..2b39bfdde6 100644 --- a/apps/desktop/src-tauri/src/commands.rs +++ b/apps/desktop/src-tauri/src/commands.rs @@ -1,8 +1,11 @@ -use crate::{audio, auth::AuthStore, config::ConfigStore, permissions}; +use crate::{audio, auth::AuthStore, config::ConfigStore, permissions, App}; use anyhow::Result; use cap_media::feeds::AudioInputFeed; -use std::path::PathBuf; -use tauri::{AppHandle, Manager}; +use std::{path::PathBuf, sync::Arc}; +use tauri::{AppHandle, Manager, State}; +use tokio::sync::RwLock; + +type MutableState<'a, T> = State<'a, Arc>>; #[tauri::command] #[specta::specta] @@ -70,16 +73,14 @@ pub fn stop_recording() { #[tauri::command] #[specta::specta] -pub fn auth_url(app: AppHandle) -> String { - let config = hypr_cloud::ClientConfig { - base_url: "https://api.hypr.com".parse().unwrap(), - auth_token: None, - }; - - let client = hypr_cloud::Client::new(config); - client +pub async fn auth_url(state: MutableState<'_, App>) -> Result { + let state = state.read().await; + let client = hypr_cloud::Client::new(state.cloud_config.clone()); + + let url = client .get_authentication_url(hypr_cloud::AuthKind::GoogleOAuth) - .to_string() + .to_string(); + Ok(url) } #[tauri::command] diff --git a/apps/desktop/src-tauri/src/lib.rs b/apps/desktop/src-tauri/src/lib.rs index 1a4720972a..38cecc6a88 100644 --- a/apps/desktop/src-tauri/src/lib.rs +++ b/apps/desktop/src-tauri/src/lib.rs @@ -14,15 +14,11 @@ mod events; mod permissions; mod session; -#[derive(specta::Type)] -#[serde(rename_all = "camelCase")] pub struct App { - #[serde(skip)] handle: AppHandle, - #[serde(skip)] audio_input_feed: Option, - #[serde(skip)] audio_input_tx: AudioInputSamplesSender, + cloud_config: hypr_cloud::ClientConfig, } #[cfg_attr(mobile, tauri::mobile_entry_point)] @@ -37,6 +33,7 @@ pub fn run() { commands::list_apple_calendars, commands::list_apple_events, permissions::open_permission_settings, + commands::auth_url, ]) .events(tauri_specta::collect_events![ events::Transcript, @@ -132,6 +129,7 @@ pub fn run() { builder // TODO: https://v2.tauri.app/plugin/updater/#building // .plugin(tauri_plugin_updater::Builder::new().build()) + .plugin(tauri_plugin_shell::init()) .invoke_handler({ let handler = specta_builder.invoke_handler(); move |invoke| handler(invoke) @@ -139,12 +137,24 @@ pub fn run() { .setup(move |app| { let app = app.handle().clone(); - if let Ok(Some(_auth)) = auth::AuthStore::load(&app) {} + let mut cloud_config = hypr_cloud::ClientConfig { + base_url: if cfg!(debug_assertions) { + "http://localhost:4000".parse().unwrap() + } else { + "https://server.hyprnote.com".parse().unwrap() + }, + auth_token: None, + }; + + if let Ok(Some(auth)) = auth::AuthStore::load(&app) { + cloud_config.auth_token = Some(auth.token); + } app.manage(RwLock::new(App { handle: app.clone(), audio_input_tx, audio_input_feed: None, + cloud_config, })); Ok(()) diff --git a/apps/desktop/src/pages/Home.tsx b/apps/desktop/src/pages/Home.tsx index 82cd580fbb..557c43dbcc 100644 --- a/apps/desktop/src/pages/Home.tsx +++ b/apps/desktop/src/pages/Home.tsx @@ -4,7 +4,9 @@ import { mockNotes } from "../mocks/data"; import { UpcomingEvents } from "../components/home/UpcomingEvents"; import { PastNotes } from "../components/home/PastNotes"; import { NewUserBanner } from "../components/home/NewUserBanner"; -import { invoke } from "@tauri-apps/api/core"; + +import { open } from "@tauri-apps/plugin-shell"; +import { commands } from "../types"; export default function Home() { const [isNewUser] = useState(true); @@ -54,12 +56,13 @@ export default function Home() {
{isNewUser && } diff --git a/apps/desktop/src/types/tauri.ts b/apps/desktop/src/types/tauri.ts index 58c8b4a680..a64a1e7477 100644 --- a/apps/desktop/src/types/tauri.ts +++ b/apps/desktop/src/types/tauri.ts @@ -29,6 +29,9 @@ export const commands = { async openPermissionSettings(permission: OSPermission): Promise { await TAURI_INVOKE("open_permission_settings", { permission }); }, + async authUrl(): Promise { + return await TAURI_INVOKE("auth_url"); + }, }; /** user-defined events **/ diff --git a/crates/cloud/src/lib.rs b/crates/cloud/src/lib.rs index 43277a6606..fd4b149edf 100644 --- a/crates/cloud/src/lib.rs +++ b/crates/cloud/src/lib.rs @@ -42,6 +42,7 @@ pub struct Client { reqwest_client: reqwest::Client, } +#[derive(Debug, Clone)] pub struct ClientConfig { pub base_url: Url, pub auth_token: Option, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 948b06a96b..ce89b3072b 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -56,6 +56,9 @@ importers: '@tauri-apps/plugin-log': specifier: ^2.2.0 version: 2.2.0 + '@tauri-apps/plugin-shell': + specifier: ^2.2.0 + version: 2.2.0 '@tauri-apps/plugin-updater': specifier: ^2.0.0 version: 2.3.0 @@ -1065,6 +1068,9 @@ packages: '@tauri-apps/plugin-log@2.2.0': resolution: {integrity: sha512-g6CsQAR1lsm5ABSZZxpM/iCn86GrMDTTlhj7GPkZkYBRSm3+WczfOAl7SV7HDn77tOKCzhZffwI5uHfRoHutrw==} + '@tauri-apps/plugin-shell@2.2.0': + resolution: {integrity: sha512-iC3Ic1hLmasoboG7BO+7p+AriSoqAwKrIk+Hpk+S/bjTQdXqbl2GbdclghI4gM32X0bls7xHzIFqhRdrlvJeaA==} + '@tauri-apps/plugin-updater@2.3.0': resolution: {integrity: sha512-qdzyZEUN69FZQ/nRx51fBub10tT6wffJl3DLVo9q922Gvw8Wk++rZhoD9eethPlZYbog/7RGgT8JkrfLh5BKAg==} @@ -2972,6 +2978,10 @@ snapshots: dependencies: '@tauri-apps/api': 2.1.1 + '@tauri-apps/plugin-shell@2.2.0': + dependencies: + '@tauri-apps/api': 2.1.1 + '@tauri-apps/plugin-updater@2.3.0': dependencies: '@tauri-apps/api': 2.1.1
<%= col[:label] %>{col[:label]} - <%= gettext("Actions") %> + {gettext("Actions")}