diff --git a/README.md b/README.md index 50cf6f8..0b50ae0 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,11 @@ # DrainCloudCore +**DrainCloud** is an opensource cloud file management service, aimed for an ease of usage in a self-hosted usage scenarios. +The main goal is to create a *easy-to-host* and very performant application with small footprint. -To start your Phoenix server: +*TODO put docs here* + +## Development +To start your DrainCloudCore 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` @@ -9,7 +14,7 @@ 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 +### Some phoenix related links * Official website: https://www.phoenixframework.org/ * Guides: https://hexdocs.pm/phoenix/overview.html diff --git a/assets/css/app.css b/assets/css/app.css index 378c8f9..f29cd30 100644 --- a/assets/css/app.css +++ b/assets/css/app.css @@ -2,4 +2,92 @@ @import "tailwindcss/components"; @import "tailwindcss/utilities"; -/* This file is for your main application CSS */ + + +body { + font-family: Arial, sans-serif; + background-color: #f7f7f7; + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; + height: 100vh; + margin: 0; +} +header { + width: 100%; + background-color: #0d1547; + padding: 15px 0; + text-align: center; + color: rgb(255, 241, 233); + font-size: 18px; + font-weight: bold; + box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); + position: fixed; + top: 0; + left: 0; + z-index: 1000; +} +.login-container { + background-color: #fff; + padding: 20px; + border-radius: 8px; + box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); + width: 300px; +} +h2 { + margin-bottom: 20px; + color: #333; + text-align: center; +} +.input-group { + margin-bottom: 15px; +} +.input-group label { + display: block; + margin-bottom: 5px; + color: #555; +} +.input-group input { + width: 100%; + padding: 10px; + border: 1px solid #ccc; + border-radius: 4px; +} +.login-button { + width: 100%; + padding: 10px; + background-color: #0d1547; + color: #fff; + border: none; + border-radius: 4px; + cursor: pointer; + font-size: 16px; +} +.login-button:hover { + background-color: #0d1547; +} + +.gallery-container { + display: grid; + grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); + grid-gap: 10px; + padding: 10px; +} +.gallery-item { + background-color: #fff; + padding: 10px; + border-radius: 8px; + box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); + text-align: center; +} +.gallery-item img { + max-width: 100%; + height: auto; + border-radius: 4px; +} +.gallery-item p { + margin-top: 10px; + font-size: 14px; + color: #555; +} \ No newline at end of file diff --git a/assets/js/app.js b/assets/js/app.js index d5e278a..8bc9b8a 100644 --- a/assets/js/app.js +++ b/assets/js/app.js @@ -42,3 +42,33 @@ liveSocket.connect() // >> liveSocket.disableLatencySim() window.liveSocket = liveSocket +function initialize_gallery() { + document.addEventListener('DOMContentLoaded', function() { + const imagePaths = [ + 'image1.jpg', + 'image2.jpg', + 'image3.jpg', + 'image4.jpg', + 'image5.jpg' + // Add more image filenames here + ]; + + const gallery = document.getElementById('gallery'); + + imagePaths.forEach(function(image) { + const item = document.createElement('div'); + item.className = 'gallery-item'; + + const img = document.createElement('img'); + img.src = '/images/' + image; + img.alt = image; + + const caption = document.createElement('p'); + caption.textContent = image; + + item.appendChild(img); + item.appendChild(caption); + gallery.appendChild(item); + }); + }); +} \ No newline at end of file diff --git a/docker-compose.yaml b/docker-compose.yaml index d295bb4..5f06def 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -9,5 +9,26 @@ services: ports: - 5432:5432 + minio: + image: quay.io/minio/minio:RELEASE.2024-08-29T01-40-52Z + command: server --console-address ":9001" http://minio/data{1...2} + hostname: minio + volumes: + - data-1:/data1 + - data-2:/data2 + expose: + - "9000" + - "9001" + environment: + MINIO_ROOT_USER: minioadmin + MINIO_ROOT_PASSWORD: minioadmin + healthcheck: + test: ["CMD", "mc", "ready", "local"] + interval: 5s + timeout: 5s + retries: 5 + volumes: - draincore-data: {} \ No newline at end of file + draincore-data: + data-1: + data-2: \ No newline at end of file diff --git a/lib/draincloud_core/application.ex b/lib/draincloud_core/application.ex index bb1e624..76b9108 100644 --- a/lib/draincloud_core/application.ex +++ b/lib/draincloud_core/application.ex @@ -10,6 +10,7 @@ defmodule DrainCloudCore.Application do children = [ DrainCloudCoreWeb.Telemetry, DrainCloudCore.Repo, + # DrainCloudCore.Rtc, {DNSCluster, query: Application.get_env(:draincloud_core, :dns_cluster_query) || :ignore}, {Phoenix.PubSub, name: DrainCloudCore.PubSub}, # Start a worker by calling: DrainCloudCore.Worker.start_link(arg) diff --git a/lib/draincloud_core/auth/auth.ex b/lib/draincloud_core/auth/auth.ex new file mode 100644 index 0000000..abf9db2 --- /dev/null +++ b/lib/draincloud_core/auth/auth.ex @@ -0,0 +1,6 @@ +defmodule DraincloudCore.Auth do + def is_logon(_token) do + # TODO here + true + end +end diff --git a/lib/draincloud_core/rtc.ex b/lib/draincloud_core/rtc.ex index 41c40b1..22e62f5 100644 --- a/lib/draincloud_core/rtc.ex +++ b/lib/draincloud_core/rtc.ex @@ -1,3 +1,103 @@ -defmodule DraincloudCore.Rtc do - # Real Time Config module +defmodule DrainCloudCore.Rtc.Application do + use Application + + def child_spec(opts) do + %{ + id: __MODULE__, + start: {__MODULE__, :start_link, [opts]}, + shutdown: 5_000, + restart: :permanent, + type: :supervisor + } + end + def start_link(_) do + children = [ + DrainCloudCore.Rtc + ] + + opts = [strategy: :one_for_one, name: DrainCloudCore.Rtc.Supervisor] + Supervisor.start_link(children, opts) + end +end + +defmodule DrainCloudCore.Rtc do + alias :mnesia, as: Mnesia + alias :logger, as: Log + + use GenServer + + # Real-time config table schemas + @config_web [attributes: [ + :host, + :enable_https, + :port, + ]] + + @config_pg [attributes: [ + :host, + :port, + :ssl, + :user, + :password, + :db, + ]] + + + @config_s3 [attributes: [ + :host, + :port, + # user / secret / secrets etc... + ]] + + # def child_spec(opts) do + # %{ + # id: __MODULE__, + # start: {__MODULE__, :start_link, [opts]}, + # shutdown: 5_000, + # restart: :permanent, + # type: :worker + # } + # end + + def start_link(default) when is_list(default) do + GenServer.start_link(__MODULE__, default) + end + + @impl true + def init(stack) do + {:ok, stack} + end + + @impl true + def handle_call(:pop, _from, [head | tail]) do + {:reply, head, tail} + end + + @impl true + def handle_cast({:push, element}, state) do + {:noreply, [element | state]} + end + + def fetch_config() do + # Mnesia.read() + end + def init() do + Log.info("[#{__MODULE__}] start initializin RTC subsystems") + + if Mnesia.create_schema([node()]) != :ok do + Log.warning("[#{__MODULE__}] schema #{node()} not created. skipping") + end + + if Mnesia.create_table(DrainCloudRtcWeb, @config_web) != {:atomic, :ok} do + Log.warning("[#{__MODULE__}] table config_web not created. skipping") + end + + if Mnesia.create_table(DrainCloudRtcPG, @config_pg) != {:atomic, :ok} do + Log.warning("[#{__MODULE__}] schema config_pg not created. skipping") + end + + if Mnesia.create_table(DrainCloudRtcS3, @config_s3) != {:atomic, :ok} do + Log.warning("[#{__MODULE__}] schema config_s3 not created. skipping") + end + end end diff --git a/lib/draincloud_core_web/components/layouts/root.html.heex b/lib/draincloud_core_web/components/layouts/root.html.heex index 83899b2..90e81b6 100644 --- a/lib/draincloud_core_web/components/layouts/root.html.heex +++ b/lib/draincloud_core_web/components/layouts/root.html.heex @@ -8,7 +8,8 @@ <%= assigns[:page_title] || "DrainCloudCore" %> - +
diff --git a/lib/draincloud_core_web/controllers/auth_controller/auth_controller.ex b/lib/draincloud_core_web/controllers/auth_controller/auth_controller.ex new file mode 100644 index 0000000..e8e681b --- /dev/null +++ b/lib/draincloud_core_web/controllers/auth_controller/auth_controller.ex @@ -0,0 +1,12 @@ +defmodule DrainCloudCoreWeb.AuthController do + use DrainCloudCoreWeb, :controller + alias DrainCloudCoreWeb.Request, as: Request + + def logon(conn, _params) do + if Request.hs_token?(conn) do + # TODO validate token here + end + + + end +end diff --git a/lib/draincloud_core_web/controllers/error_html.ex b/lib/draincloud_core_web/controllers/errors/error_html.ex similarity index 100% rename from lib/draincloud_core_web/controllers/error_html.ex rename to lib/draincloud_core_web/controllers/errors/error_html.ex diff --git a/lib/draincloud_core_web/controllers/error_json.ex b/lib/draincloud_core_web/controllers/errors/error_json.ex similarity index 100% rename from lib/draincloud_core_web/controllers/error_json.ex rename to lib/draincloud_core_web/controllers/errors/error_json.ex diff --git a/lib/draincloud_core_web/controllers/main_controller/main_controller.ex b/lib/draincloud_core_web/controllers/main_controller/main_controller.ex new file mode 100644 index 0000000..7a93c37 --- /dev/null +++ b/lib/draincloud_core_web/controllers/main_controller/main_controller.ex @@ -0,0 +1,11 @@ +defmodule DrainCloudCoreWeb.MainController do + use DrainCloudCoreWeb, :controller + + def test(conn, _params) do + conn + |> put_resp_content_type("application/json") + |> put_root_layout(false) + |> json(%{data: %{name: "Some Name"}}) + end + +end diff --git a/lib/draincloud_core_web/controllers/page_controller.ex b/lib/draincloud_core_web/controllers/page_controller.ex deleted file mode 100644 index 3fc85aa..0000000 --- a/lib/draincloud_core_web/controllers/page_controller.ex +++ /dev/null @@ -1,9 +0,0 @@ -defmodule DrainCloudCoreWeb.PageController do - use DrainCloudCoreWeb, :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/lib/draincloud_core_web/controllers/page_html.ex b/lib/draincloud_core_web/controllers/page_html.ex deleted file mode 100644 index 7d0f998..0000000 --- a/lib/draincloud_core_web/controllers/page_html.ex +++ /dev/null @@ -1,10 +0,0 @@ -defmodule DrainCloudCoreWeb.PageHTML do - @moduledoc """ - This module contains pages rendered by PageController. - - See the `page_html` directory for all templates available. - """ - use DrainCloudCoreWeb, :html - - embed_templates "page_html/*" -end diff --git a/lib/draincloud_core_web/controllers/page_html/home.html.heex b/lib/draincloud_core_web/controllers/page_html/home.html.heex deleted file mode 100644 index 3b2634d..0000000 --- a/lib/draincloud_core_web/controllers/page_html/home.html.heex +++ /dev/null @@ -1 +0,0 @@ -