Skip to content

Commit

Permalink
Works implementation
Browse files Browse the repository at this point in the history
wip use put_assoc for WorkUploads

got update working!

dragdrop reordering

work upload removal support

test &c fixes

more test fixing

Add opengraph etc stuff to header

Add stuff to creation page too

work listing on the discover page

checkpointing offering configuration

offering configuration for works

portfolio

fix preview item when there's only one

migrate away from scss and start moving css out of <style> tags

migrate to standalone css files for styling

redo works page to be masonry-style columns

styling tweaks

tweak

WorkGallery component for shared rendering behavior

replace offering gallery with works gallery

move to simpleicons for social brand icons and start minifying css

show upload-related errors for work uploads

remove WorkCard

fix new_offering in seeds.exs

support showcasing works to prioritize their display

fix issue with New Work button overflowing to next column

add 'Related Works' to Work page, plus some other niceties

remove stray inspect

try and get watching working for css?

css tweaks

fix regex

misc tweaks to commission styling stuff

get live reload for css working

add support for creating works from commissions' final invoices

sketch out migrators (not tested yet)

fix migrators a bit

make migrators be Workers

initial stab at trigger-based upload deletion

automated upload deletion through periodic garbage collection

deletion button for works

cleanup pass

tests passing
  • Loading branch information
zkat committed Mar 31, 2024
1 parent 49a69a0 commit 2f377d3
Show file tree
Hide file tree
Showing 82 changed files with 6,476 additions and 2,723 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ jobs:
priv/plts
key: ${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-${{ hashFiles('mix.lock') }}

- name: Install FFmpeg
uses: FedericoCarboni/setup-ffmpeg@v3

- name: Run test
run: mix coveralls.github --trace --slowest 10
env:
Expand Down
24 changes: 8 additions & 16 deletions assets/css/app.scss → assets/css/app.css
Original file line number Diff line number Diff line change
@@ -1,24 +1,16 @@
$fa-font-path: "../node_modules/@fortawesome/fontawesome-free/webfonts/";
@import "../node_modules/tailwindcss/base.css";
@import "../node_modules/tailwindcss/components.css";
@import "../node_modules/tailwindcss/utilities.css";

@import "../node_modules/@fortawesome/fontawesome-free/scss/fontawesome.scss";
@import "../node_modules/@fortawesome/fontawesome-free/scss/regular.scss";
@import "../node_modules/@fortawesome/fontawesome-free/scss/solid.scss";
@import "../node_modules/@fortawesome/fontawesome-free/scss/brands.scss";
@import "../node_modules/@fortawesome/fontawesome-free/scss/v4-shims.scss";
@import "../node_modules/quill/dist/quill.snow.css";

@import "../node_modules/tailwindcss/base";
@import "../node_modules/tailwindcss/components";
@import "../node_modules/tailwindcss/utilities";
@import "../node_modules/@splidejs/splide/dist/css/themes/splide-default.min.css";

@import "../node_modules/quill/dist/quill.snow";
@import "../node_modules/cropperjs/dist/cropper.css";

@import "../node_modules/@splidejs/splide/src/css/themes/default/index";
@import "./spotlight.css";

@import "../node_modules/cropperjs/dist/cropper";

@import "./spotlight";

@import "_components";
@import "_components.css";

:root {
--rounded-box: 1rem; /* border-radius for cards and other big elements */
Expand Down
5,141 changes: 3,357 additions & 1,784 deletions assets/package-lock.json

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions assets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
"description": " ",
"license": "MIT",
"scripts": {
"deploy:css": "cross-env NODE_ENV=production postcss css/app.scss -o ../priv/static/assets/app.css",
"deploy:css": "cross-env NODE_ENV=production postcss css/app.css -o ../priv/static/assets/app.css",
"deploy": "cd .. && mix assets.deploy && rm -rf _build/esbuild"
},
"dependencies": {
"@fortawesome/fontawesome-free": "^6.1.1",
"@tailwindcss/aspect-ratio": "^0.4.0",
"@tailwindcss/forms": "^0.4.0",
"@tailwindcss/typography": "^0.5.0",
"cropperjs": "^1.5.12",
"cssnano": "^6.1.1",
"daisyui": "^2.52.0",
"dompurify": "^3.0.5",
"lit": "^2.8.0",
Expand All @@ -21,20 +21,20 @@
"phoenix_html": "file:../deps/phoenix_html",
"phoenix_live_view": "file:../deps/phoenix_live_view",
"phoenix_typed_hook": "^0.18.2",
"postcss-dart-sass": "^1.0.0",
"postcss-import": "^16.1.0",
"quill": "^1.3.7",
"sortablejs": "^1.15.2",
"spotlight.js": "^0.7.8",
"topbar": "^0.1.4",
"turndown": "^7.1.2"
},
"devDependencies": {
"@splidejs/splide": "^4.0.7",
"autoprefixer": "^10.4.2",
"autoprefixer": "^10.4.19",
"cross-env": "^7.0.3",
"postcss": "^8.4.31",
"postcss-cli": "^9.0.1",
"postcss-scss": "^4.0.1",
"postcss": "^8.4.35",
"postcss-cli": "^11.0.0",
"postcss-url": "^10.1.3",
"tailwindcss": "^3.0.15"
"tailwindcss": "^3.4.1"
}
}
7 changes: 4 additions & 3 deletions assets/postcss.config.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
module.exports = {
syntax: 'postcss-scss',
plugins: {
'postcss-dart-sass': {},
'postcss-import': {},
'cssnano': { preset: 'default' },
'tailwindcss/nesting': {},
tailwindcss: {},
autoprefixer: {},
'postcss-url': {
url: 'inline',
}
}
}
};
1 change: 0 additions & 1 deletion assets/tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ const colors = require('tailwindcss/colors');

module.exports = {
mode: "jit",
purge: ["./js/**/*.{js,ts}", "../lib/*_web/**/*.*ex"],
content:
["./js/**/*.{js,ts}", "../lib/*_web.ex", "../lib/*_web/**/*.*ex"],
plugins: [
Expand Down
3 changes: 2 additions & 1 deletion config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ config :banchan, Oban,
pruning: 1,
invoice_purge: 10,
upload_cleanup: 10,
backup: 1
backup: 1,
migration: 20
]

config :sentry,
Expand Down
12 changes: 8 additions & 4 deletions config/dev.exs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ config :banchan, BanchanWeb.Endpoint,
esbuild: {Esbuild, :install_and_run, [:catalogue, ~w(--sourcemap=inline --watch)]},
node: [
"node_modules/postcss-cli/index.js",
"css/app.scss",
"css/app.css",
"--output=../priv/static/assets/app.css",
"--watch",
cd: Path.expand("../assets", __DIR__)
Expand Down Expand Up @@ -59,11 +59,15 @@ config :banchan, BanchanWeb.Endpoint,
patterns: [
~r"priv/static/.*(js|css|png|jpeg|jpg|gif|svg)$",
~r"priv/gettext/.*(po)$",
~r"priv/posts/*/.*(md)$",
~r"lib/banchan_web/(live|views|components)/.*(ex|js)$",
~r"priv/posts/.*(md)$",
~r"lib/banchan_web/(live|views|components)/.*(ex|js|ts)$",
~r"lib/banchan_web/templates/.*(eex)$",
~r"lib/banchan_web/live/.*(sface)$",
~r"priv/catalogue/.*(ex)$"
],
notify: [
live_view: [
~r"lib/banchan_web/(live|views|components)/.*(css|sface)$"
]
]
]

Expand Down
65 changes: 11 additions & 54 deletions lib/banchan/accounts/accounts.ex
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ defmodule Banchan.Accounts do

alias Banchan.Repo
alias Banchan.Uploads
alias Banchan.Uploads.Upload
alias Banchan.Workers.{EnableUser, Thumbnailer, UploadDeleter}
alias Banchan.Workers.{EnableUser, Thumbnailer}

alias BanchanWeb.UserAuth

Expand Down Expand Up @@ -825,27 +824,6 @@ defmodule Banchan.Accounts do
end,
returning: true
)
|> Ecto.Multi.run(:remove_old_pfp_img, fn _, %{updated_user: updated, user: old} ->
if old.pfp_img_id && old.pfp_img_id != updated.pfp_img_id do
UploadDeleter.schedule_deletion(%Upload{id: old.pfp_img_id})
else
{:ok, nil}
end
end)
|> Ecto.Multi.run(:remove_old_pfp_thumb, fn _, %{updated_user: updated, user: old} ->
if old.pfp_thumb_id && old.pfp_thumb_id != updated.pfp_thumb_id do
UploadDeleter.schedule_deletion(%Upload{id: old.pfp_thumb_id})
else
{:ok, nil}
end
end)
|> Ecto.Multi.run(:remove_old_header_img, fn _, %{updated_user: updated, user: old} ->
if old.header_img_id && old.header_img_id != updated.header_img_id do
UploadDeleter.schedule_deletion(%Upload{id: old.header_img_id})
else
{:ok, nil}
end
end)
|> Repo.transaction()
|> case do
{:ok, %{updated_user: user}} ->
Expand Down Expand Up @@ -1788,38 +1766,17 @@ defmodule Banchan.Accounts do
def prune_users do
now = NaiveDateTime.utc_now()

Repo.transaction(fn ->
from(
u in User,
where: not is_nil(u.deactivated_at),
where: u.deactivated_at < datetime_add(^now, -30, "day")
)
|> Repo.stream()
|> Enum.reduce(0, fn user, acc ->
# NB(@zkat): We hard match on `{:ok, _}` here because scheduling
# deletions should really never fail.
if user.pfp_img_id do
{:ok, _} = UploadDeleter.schedule_deletion(%Upload{id: user.pfp_img_id})
end

if user.pfp_thumb_id do
{:ok, _} = UploadDeleter.schedule_deletion(%Upload{id: user.pfp_thumb_id})
end

if user.header_img_id do
{:ok, _} = UploadDeleter.schedule_deletion(%Upload{id: user.header_img_id})
end

case Repo.delete(user) do
{:ok, _} ->
acc + 1

{:error, error} ->
Logger.error("Failed to prune user #{user.handle}: #{inspect(error)}")
acc
end
{:ok, {count, _}} =
Repo.transaction(fn ->
from(
u in User,
where: not is_nil(u.deactivated_at),
where: u.deactivated_at < datetime_add(^now, -30, "day")
)
|> Repo.delete_all()
end)
end)

{:ok, count}
end

@doc """
Expand Down
7 changes: 6 additions & 1 deletion lib/banchan/accounts/user.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ defmodule Banchan.Accounts.User do
alias Banchan.Notifications.{UserNotification, UserNotificationSettings}
alias Banchan.Studios.Studio
alias Banchan.Uploads.Upload
alias Banchan.Works.Work

@derive {Inspect, except: [:password]}
schema "users" do
Expand Down Expand Up @@ -67,6 +68,8 @@ defmodule Banchan.Accounts.User do

has_many :notifications, UserNotification

has_many :works, Work, foreign_key: :client_id

many_to_many :studios, Studio, join_through: "users_studios"

timestamps()
Expand Down Expand Up @@ -117,7 +120,9 @@ defmodule Banchan.Accounts.User do
:roles,
:confirmed_at,
:totp_secret,
:totp_activated
:totp_activated,
:mature_ok,
:muted
])
|> validate_handle(:handle)
|> validate_required([:email])
Expand Down
5 changes: 4 additions & 1 deletion lib/banchan/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ defmodule Banchan.Application do
# {Banchan.Worker, arg}
# GenServer for managing foreign exchange rate fetching.
{Banchan.Payments.Forex,
name: Banchan.Payments.Forex, base_currency: Banchan.Payments.platform_currency()}
name: Banchan.Payments.Forex, base_currency: Banchan.Payments.platform_currency()},
# GenServer that listens to Uploads getting deleted and queues deleting
# their data.
Banchan.Uploads.UploadDeleteListener
]

:ok = Oban.Telemetry.attach_default_logger()
Expand Down
2 changes: 2 additions & 0 deletions lib/banchan/commissions/commission.ex
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ defmodule Banchan.Commissions.Commission do

has_many :events, Banchan.Commissions.Event, preload_order: [asc: :inserted_at, asc: :id]

has_one :work, Banchan.Works.Work

belongs_to :offering, Banchan.Offerings.Offering
belongs_to :studio, Banchan.Studios.Studio
belongs_to :client, Banchan.Accounts.User
Expand Down
41 changes: 7 additions & 34 deletions lib/banchan/commissions/commissions.ex
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ defmodule Banchan.Commissions do
alias Banchan.Studios
alias Banchan.Studios.Studio
alias Banchan.Uploads
alias Banchan.Uploads.Upload
alias Banchan.Workers.{Thumbnailer, UploadDeleter}
alias Banchan.Workers.Thumbnailer

## Events

Expand Down Expand Up @@ -306,7 +305,8 @@ defmodule Banchan.Commissions do
:studio,
events: [invoice: [], attachments: [:upload, :thumbnail, :preview]],
line_items: [:option],
offering: [:options, :studio]
offering: [:options, :studio],
work: []
]
)
end
Expand Down Expand Up @@ -713,7 +713,7 @@ defmodule Banchan.Commissions do

if close do
{:ok, offering} =
Offerings.update_offering(Accounts.system_user(), offering, %{open: false}, nil)
Offerings.update_offering(Accounts.system_user(), offering, %{open: false})

offering
else
Expand Down Expand Up @@ -928,7 +928,7 @@ defmodule Banchan.Commissions do

if close do
{:ok, _} =
Offerings.update_offering(Accounts.system_user(), offering, %{open: false}, nil)
Offerings.update_offering(Accounts.system_user(), offering, %{open: false})
end
end

Expand Down Expand Up @@ -1342,34 +1342,7 @@ defmodule Banchan.Commissions do
%Event{} = event,
%EventAttachment{} = event_attachment
) do
Ecto.Multi.new()
|> Ecto.Multi.run(:delete_upload, fn _, _ ->
if event_attachment.upload_id do
UploadDeleter.schedule_deletion(%Upload{id: event_attachment.upload_id})
else
{:ok, nil}
end
end)
|> Ecto.Multi.run(:delete_preview, fn _, _ ->
if event_attachment.preview_id do
UploadDeleter.schedule_deletion(%Upload{id: event_attachment.preview_id},
keep_original: true
)
else
{:ok, nil}
end
end)
|> Ecto.Multi.run(:delete_thumbnail, fn _, _ ->
if event_attachment.thumbnail_id do
UploadDeleter.schedule_deletion(%Upload{id: event_attachment.thumbnail_id},
keep_original: true
)
else
{:ok, nil}
end
end)
|> Ecto.Multi.delete(:delete_event_attachment, event_attachment)
|> Repo.transaction()
Repo.delete(event_attachment)
|> case do
{:ok, _} ->
new_attachments = Enum.reject(event.attachments, &(&1.id == event_attachment.id))
Expand All @@ -1382,7 +1355,7 @@ defmodule Banchan.Commissions do

{:ok, event_attachment}

{:error, _, error, _} ->
{:error, error} ->
{:error, error}
end
end
Expand Down
3 changes: 3 additions & 0 deletions lib/banchan/offerings/gallery_image.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
defmodule Banchan.Offerings.GalleryImage do
@moduledoc """
Schema for gallery images associated with offerings.
DEPRECATED: This is no longer used, but is kept around for data migration
purposes.
"""
use Ecto.Schema

Expand Down
Loading

0 comments on commit 2f377d3

Please sign in to comment.