Skip to content

Commit

Permalink
Merge pull request #3 from Syfaro/merged-media
Browse files Browse the repository at this point in the history
Support merging media
  • Loading branch information
Syfaro authored Feb 7, 2024
2 parents 2168d0f + cd15795 commit 1c75824
Show file tree
Hide file tree
Showing 50 changed files with 1,951 additions and 1,303 deletions.
62 changes: 62 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ chrono = { version = "0.4", features = ["serde"] }
clap = { version = "4", features = ["derive", "env", "cargo", "wrap_help"] }
dotenv = { version = "0.15", optional = true }
egg-mode = "0.16"
enum-map = "~2.0.1"
faktory = "0.12"
futures = "0.3"
hex = "0.4"
Expand Down Expand Up @@ -84,7 +85,7 @@ furaffinity-rs = { git = "https://github.com/Syfaro/furaffinity-rs.git" }
fuzzysearch = { git = "https://github.com/Syfaro/fuzzysearch-rs.git", features = ["trace", "local_hash"] }
tgbotapi = { git = "https://github.com/Syfaro/tgbotapi-rs.git" }

foxlib = { git = "https://github.com/Syfaro/foxlib.git", features = ["jobs"] }
foxlib = { git = "https://github.com/Syfaro/foxlib.git", features = ["jobs", "flags", "flags-openssl"] }
fuzzysearch-common = { git = "https://github.com/Syfaro/fuzzysearch.git", features = ["queue"] }

[dependencies.sqlx]
Expand Down
5 changes: 5 additions & 0 deletions assets/css/bootstrap-icons.min.css

Large diffs are not rendered by default.

Binary file added assets/fonts/bootstrap-icons.woff
Binary file not shown.
Binary file added assets/fonts/bootstrap-icons.woff2
Binary file not shown.
16 changes: 12 additions & 4 deletions assets/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ function subscribeToEvents() {

subscribeToEvents();

const dtf = new Intl.DateTimeFormat('en', { timeStyle: 'medium', dateStyle: 'medium' });
const rtf = new Intl.RelativeTimeFormat('en', { numeric: 'auto' });

const units = {
Expand All @@ -188,14 +189,14 @@ function getRelativeTime(toDate, fromDate = new Date()) {

function updateRelativeTimes() {
[...document.querySelectorAll('.relative-time[data-timestamp]')].forEach((elem) => {
const timestamp = parseInt(elem.dataset.timestamp, 10);
const date = new Date(timestamp * 1000);

if (!elem.dataset.replacedText) {
elem.title = elem.textContent.trim();
elem.dataset.tooltip = dtf.format(date);
elem.dataset.replacedText = true;
}

const timestamp = parseInt(elem.dataset.timestamp, 10);
const date = new Date(timestamp * 1000);

elem.textContent = getRelativeTime(date);
});

Expand All @@ -204,6 +205,13 @@ function updateRelativeTimes() {

updateRelativeTimes();

[...document.querySelectorAll('.absolute-time[data-timestamp]')].forEach((elem) => {
const timestamp = parseInt(elem.dataset.timestamp, 10);
const date = new Date(timestamp * 1000);

elem.textContent = dtf.format(date);
});

[...document.querySelectorAll('input[type=file]')].forEach((input) => {
input.addEventListener('change', () => {
const uploadButton = document.querySelector(input.dataset.uploadButton);
Expand Down
13 changes: 12 additions & 1 deletion content/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
# Changelog

## v0.17.2 — Noveber 12th, 2023
## v0.18.0 — February 7th, 2024

* Added ability to merge multiple images into one entry.
* Added beta feature opt-in ability.
* Improved media addition by automatically grouping identical files.
* Improved automatic imports to also search for previous uploads.
* Improved how dates are displayed.
* Improved UI with iconography.
* Fixed an issue that could cause Bluesky posts to stop processing.
* Internal updates.

## v0.17.2 — November 12th, 2023

* Improved Bluesky support with direct federated server access.
* Fixed an issue where background tasks could reduce site responsiveness.
Expand Down
3 changes: 3 additions & 0 deletions migrations/20240206184335_merged_media.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
DROP VIEW owned_media_item_accounts;

DROP TABLE owned_media_item_account;
59 changes: 59 additions & 0 deletions migrations/20240206184335_merged_media.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
CREATE TABLE owned_media_item_account (
owned_media_item_id uuid NOT NULL REFERENCES owned_media_item (id) ON DELETE CASCADE,
account_id uuid NOT NULL REFERENCES linked_account (id) ON DELETE CASCADE,
source_id text NOT NULL,
link text NOT NULL,
title text,
posted_at timestamp with time zone,
created_at timestamp with time zone NOT NULL DEFAULT current_timestamp,
PRIMARY KEY (owned_media_item_id, account_id, source_id)
);

CREATE INDEX owned_media_item_account_lookup_idx ON owned_media_item_account (account_id, source_id);

CREATE VIEW owned_media_item_accounts (
id,
owner_id,
perceptual_hash,
sha256_hash,
last_modified,
content_url,
content_size,
thumb_url,
event_count,
last_event,
accounts
) AS
SELECT
owned_media_item.id,
owned_media_item.owner_id,
owned_media_item.perceptual_hash,
owned_media_item.sha256_hash,
owned_media_item.last_modified,
owned_media_item.content_url,
owned_media_item.content_size,
owned_media_item.thumb_url,
owned_media_item.event_count,
owned_media_item.last_event,
jsonb_agg(
jsonb_build_object(
'account_id',
owned_media_item_account.account_id,
'source_id',
owned_media_item_account.source_id,
'link',
owned_media_item_account.link,
'title',
owned_media_item_account.title,
'posted_at',
owned_media_item_account.posted_at
)
) FILTER (
WHERE
owned_media_item_account.owned_media_item_id IS NOT NULL
) accounts
FROM
owned_media_item
LEFT JOIN owned_media_item_account ON owned_media_item.id = owned_media_item_account.owned_media_item_id
GROUP BY
owned_media_item.id;
2 changes: 2 additions & 0 deletions migrations/20240207174745_tester_opt_in.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE
user_account DROP COLUMN is_tester;
4 changes: 4 additions & 0 deletions migrations/20240207174745_tester_opt_in.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ALTER TABLE
user_account
ADD
COLUMN is_tester boolean NOT NULL DEFAULT false;
20 changes: 20 additions & 0 deletions queries/admin/migrate_owned_media_account.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
INSERT INTO
owned_media_item_account (
owned_media_item_id,
account_id,
source_id,
link,
title,
posted_at
)
SELECT
id,
account_id,
source_id,
link,
title,
posted_at
FROM
owned_media_item
WHERE
account_id IS NOT NULL;
3 changes: 2 additions & 1 deletion queries/linked_account/items.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ SELECT
coalesce(sum(content_size)::bigint, 0) "total_content_size!"
FROM
owned_media_item
JOIN owned_media_item_account ON owned_media_item.id = owned_media_item_account.owned_media_item_id
WHERE
owner_id = $1
AND account_id = $2;
AND owned_media_item_account.account_id = $2;
17 changes: 0 additions & 17 deletions queries/linked_account/move_media_to_delete.sql

This file was deleted.

20 changes: 1 addition & 19 deletions queries/owned_media/add_item.sql
Original file line number Diff line number Diff line change
@@ -1,32 +1,14 @@
INSERT INTO
owned_media_item (
owner_id,
account_id,
source_id,
perceptual_hash,
sha256_hash,
link,
title,
posted_at,
last_modified
)
VALUES
(
$1,
$2,
$3,
$4,
$5,
$6,
$7,
$8,
current_timestamp
) ON CONFLICT (account_id, source_id) DO
UPDATE
SET
perceptual_hash = EXCLUDED.perceptual_hash,
sha256_hash = EXCLUDED.sha256_hash,
link = EXCLUDED.link,
title = EXCLUDED.title,
posted_at = EXCLUDED.posted_at,
last_modified = EXCLUDED.last_modified RETURNING id;
) RETURNING id;
8 changes: 2 additions & 6 deletions queries/owned_media/add_manual_item.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,12 @@ INSERT INTO
owner_id,
perceptual_hash,
sha256_hash,
posted_at,
last_modified,
title
last_modified
)
VALUES
(
$1,
$2,
$3,
current_timestamp,
current_timestamp,
$4
current_timestamp
) RETURNING id;
20 changes: 8 additions & 12 deletions queries/owned_media/find_similar.sql
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
SELECT
id,
owner_id,
account_id,
source_id,
id "id!",
owner_id "owner_id!",
perceptual_hash,
sha256_hash "sha256_hash: Sha256Hash",
link,
title,
posted_at,
last_modified,
sha256_hash "sha256_hash!: Sha256Hash",
last_modified "last_modified!",
content_url,
content_size,
thumb_url,
event_count,
last_event
event_count "event_count!",
last_event,
accounts "accounts: sqlx::types::Json<Vec<OwnedMediaItemAccount>>"
FROM
owned_media_item
owned_media_item_accounts
WHERE
perceptual_hash <@ ($1, $2);
Loading

0 comments on commit 1c75824

Please sign in to comment.