diff --git a/alembic/versions/158973fda20f_lower_filegroup_primary_path.py b/alembic/versions/158973fda20f_lower_filegroup_primary_path.py new file mode 100644 index 00000000..850d12bc --- /dev/null +++ b/alembic/versions/158973fda20f_lower_filegroup_primary_path.py @@ -0,0 +1,26 @@ +"""Lower FileGroup.primary_path + +Revision ID: 158973fda20f +Revises: 69e9754d1a63 +Create Date: 2025-08-16 10:54:58.874094 + +""" +import os +from alembic import op +from sqlalchemy.orm import Session + +# revision identifiers, used by Alembic. +revision = '158973fda20f' +down_revision = '69e9754d1a63' +branch_labels = None +depends_on = None + +DOCKERIZED = True if os.environ.get('DOCKER', '').lower().startswith('t') else False + + +def upgrade(): + op.execute('CREATE INDEX file_group_primary_path_lower_idx ON file_group (LOWER(primary_path))') + + +def downgrade(): + op.execute('DROP INDEX IF EXISTS file_group_primary_path_lower_idx') diff --git a/alembic/versions/4f03b9548f6e_file_group_effective_date_trigger.py b/alembic/versions/4f03b9548f6e_file_group_effective_date_trigger.py new file mode 100644 index 00000000..61945eaa --- /dev/null +++ b/alembic/versions/4f03b9548f6e_file_group_effective_date_trigger.py @@ -0,0 +1,47 @@ +"""file_group.effective_date trigger + +Revision ID: 4f03b9548f6e +Revises: 54c19aa847da +Create Date: 2025-08-17 10:49:35.754548 + +""" +import os +from alembic import op +from sqlalchemy.orm import Session + +# revision identifiers, used by Alembic. +revision = '4f03b9548f6e' +down_revision = '54c19aa847da' +branch_labels = None +depends_on = None + + +def upgrade(): + # Create trigger function + op.execute(""" + CREATE OR REPLACE FUNCTION update_effective_datetime() + RETURNS TRIGGER AS + $$ + BEGIN + NEW.effective_datetime = COALESCE(NEW.published_datetime, NEW.download_datetime); + RETURN NEW; + END; + $$ LANGUAGE plpgsql; + """) + + # Create trigger + op.execute(""" + CREATE TRIGGER file_group_effective_datetime_trigger + BEFORE INSERT OR UPDATE OF published_datetime, download_datetime + ON file_group + FOR EACH ROW + EXECUTE FUNCTION update_effective_datetime(); + """) + + +def downgrade(): + # Drop trigger + op.execute("DROP TRIGGER IF EXISTS file_group_effective_datetime_trigger ON file_group") + + # Drop trigger function + op.execute("DROP FUNCTION IF EXISTS update_effective_datetime") diff --git a/alembic/versions/54c19aa847da_channel_summary_indexes.py b/alembic/versions/54c19aa847da_channel_summary_indexes.py new file mode 100644 index 00000000..dc00e745 --- /dev/null +++ b/alembic/versions/54c19aa847da_channel_summary_indexes.py @@ -0,0 +1,145 @@ +"""Channel summary columns, triggers and indexes. + +Revision ID: 54c19aa847da +Revises: 158973fda20f +Create Date: 2025-08-16 11:45:48.190427 + +""" +from alembic import op +import sqlalchemy as sa + +# revision identifiers, used by Alembic. +revision = '54c19aa847da' +down_revision = '158973fda20f' +branch_labels = None +depends_on = None + + +def upgrade(): + # Add columns + op.execute(""" + ALTER TABLE channel + ADD COLUMN video_count INTEGER DEFAULT 0 NOT NULL, + ADD COLUMN total_size BIGINT DEFAULT 0 NOT NULL, + ADD COLUMN minimum_frequency INTEGER; + """) + + # Populate columns + op.execute(""" + UPDATE channel + SET video_count = (SELECT COUNT(*) + FROM video + WHERE channel_id = channel.id), + total_size = (SELECT COALESCE(SUM(fg.size), 0)::BIGINT + FROM video v + LEFT JOIN file_group fg ON v.file_group_id = fg.id + WHERE v.channel_id = channel.id), + minimum_frequency = (SELECT MIN(frequency) + FROM download + WHERE channel_id = channel.id); + """) + + # Create trigger functions + op.execute(""" + CREATE OR REPLACE FUNCTION update_channel_video_count() + RETURNS TRIGGER AS + $$ + BEGIN + UPDATE channel + SET video_count = (SELECT COUNT(*) FROM video WHERE channel_id = NEW.channel_id) + WHERE id = NEW.channel_id; + RETURN NEW; + END; + $$ LANGUAGE plpgsql; + """) + op.execute(""" + CREATE OR REPLACE FUNCTION update_channel_size() + RETURNS TRIGGER AS + $$ + BEGIN + UPDATE channel + SET total_size = (SELECT COALESCE(SUM(fg.size), 0)::BIGINT + FROM video v + LEFT JOIN file_group fg ON v.file_group_id = fg.id + WHERE v.channel_id = NEW.id) + WHERE id = NEW.id; + RETURN NEW; + END; + $$ LANGUAGE plpgsql; + """) + op.execute(""" + CREATE OR REPLACE FUNCTION update_channel_minimum_frequency() + RETURNS TRIGGER AS + $$ + BEGIN + UPDATE channel + SET minimum_frequency = (SELECT MIN(frequency) FROM download WHERE channel_id = NEW.channel_id) + WHERE id = NEW.channel_id; + RETURN NEW; + END; + $$ LANGUAGE plpgsql; + """) + + # Create triggers + op.execute(""" + CREATE TRIGGER video_count_trigger + AFTER INSERT OR DELETE + ON video + FOR EACH ROW + EXECUTE FUNCTION update_channel_video_count(); + """) + op.execute(""" + CREATE TRIGGER video_size_trigger + AFTER INSERT OR DELETE + ON video + FOR EACH ROW + EXECUTE FUNCTION update_channel_size(); + """) + op.execute(""" + CREATE TRIGGER file_group_size_trigger + AFTER UPDATE OF size + ON file_group + FOR EACH ROW + WHEN (OLD.size IS DISTINCT FROM NEW.size) + EXECUTE FUNCTION update_channel_size(); + """) + op.execute(""" + CREATE TRIGGER download_frequency_trigger + AFTER INSERT OR UPDATE OF frequency OR DELETE + ON download + FOR EACH ROW + EXECUTE FUNCTION update_channel_minimum_frequency(); + """) + + # Create indexes + op.execute(""" + CREATE INDEX channel_video_count_idx ON channel (video_count); + CREATE INDEX channel_total_size_idx ON channel (total_size); + CREATE INDEX channel_minimum_frequency_idx ON channel (minimum_frequency); + """) + + +def downgrade(): + # Drop triggers + op.execute("DROP TRIGGER IF EXISTS video_count_trigger ON video;") + op.execute("DROP TRIGGER IF EXISTS video_size_trigger ON video;") + op.execute("DROP TRIGGER IF EXISTS file_group_size_trigger ON file_group;") + op.execute("DROP TRIGGER IF EXISTS download_frequency_trigger ON download;") + + # Drop trigger functions + op.execute("DROP FUNCTION IF EXISTS update_channel_video_count;") + op.execute("DROP FUNCTION IF EXISTS update_channel_size;") + op.execute("DROP FUNCTION IF EXISTS update_channel_minimum_frequency;") + + # Drop indexes + op.execute("DROP INDEX IF EXISTS channel_minimum_frequency_idx;") + op.execute("DROP INDEX IF EXISTS channel_total_size_idx;") + op.execute("DROP INDEX IF EXISTS channel_video_count_idx;") + + # Drop columns + op.execute(""" + ALTER TABLE channel + DROP COLUMN IF EXISTS minimum_frequency, + DROP COLUMN IF EXISTS total_size, + DROP COLUMN IF EXISTS video_count; + """) diff --git a/alembic/versions/69e9754d1a63_filegroup_effective_datetime.py b/alembic/versions/69e9754d1a63_filegroup_effective_datetime.py new file mode 100644 index 00000000..d4bd15ca --- /dev/null +++ b/alembic/versions/69e9754d1a63_filegroup_effective_datetime.py @@ -0,0 +1,37 @@ +"""FileGroup.effective_datetime + +Revision ID: 69e9754d1a63 +Revises: f7229a67e333 +Create Date: 2025-08-16 10:28:42.661108 + +""" +import os +from alembic import op +from sqlalchemy.orm import Session + +# revision identifiers, used by Alembic. +revision = '69e9754d1a63' +down_revision = 'f7229a67e333' +branch_labels = None +depends_on = None + +DOCKERIZED = True if os.environ.get('DOCKER', '').lower().startswith('t') else False + + +def upgrade(): + op.execute('ALTER TABLE file_group ADD COLUMN IF NOT EXISTS effective_datetime TIMESTAMPTZ') + + # Populating effective_datetime for existing rows + op.execute(""" + UPDATE file_group + SET effective_datetime = COALESCE(published_datetime, download_datetime) + WHERE published_datetime IS NOT NULL + OR download_datetime IS NOT NULL; + """) + + op.execute('CREATE INDEX IF NOT EXISTS file_group_effective_datetime_idx ON file_group(effective_datetime)') + + +def downgrade(): + op.execute('DROP INDEX IF EXISTS file_group_effective_datetime_idx') + op.execute('ALTER TABLE file_group DROP COLUMN IF EXISTS effective_datetime') diff --git a/app/package-lock.json b/app/package-lock.json index b4f234f0..d7f8cc27 100644 --- a/app/package-lock.json +++ b/app/package-lock.json @@ -2236,12 +2236,14 @@ } }, "node_modules/@cypress/request/node_modules/form-data": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.1.tgz", - "integrity": "sha512-tzN8e4TX8+kkxGPK8D5u0FNmjPUjw3lwC9lSLxxoB/+GtsJG91CO8bSWy73APlgAZzZbXEYZJuxjkHH2w+Ezhw==", + "version": "4.0.4", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.4.tgz", + "integrity": "sha512-KrGhL9Q4zjj0kiUt5OO4Mr/A/jlI2jDYs5eHBpYHPcBEVSiipAvn2Ko2HnPe20rmcuuvMHNdZFp+4IlGTMF0Ow==", "dependencies": { "asynckit": "^0.4.0", "combined-stream": "^1.0.8", + "es-set-tostringtag": "^2.1.0", + "hasown": "^2.0.2", "mime-types": "^2.1.12" }, "engines": { @@ -5574,6 +5576,18 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/call-bind-apply-helpers": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/call-bind-apply-helpers/-/call-bind-apply-helpers-1.0.2.tgz", + "integrity": "sha512-Sp1ablJ0ivDkSzjcaJdxEunN5/XvksFJ2sMBFfq6x0ryhQV/2b/KwFe21cMpmHtPOSij8K99/wSfoEuTObmuMQ==", + "dependencies": { + "es-errors": "^1.3.0", + "function-bind": "^1.1.2" + }, + "engines": { + "node": ">= 0.4" + } + }, "node_modules/callsites": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/callsites/-/callsites-3.1.0.tgz", @@ -7164,6 +7178,19 @@ "resolved": "https://registry.npmjs.org/draco3d/-/draco3d-1.5.6.tgz", "integrity": "sha512-+3NaRjWktb5r61ZFoDejlykPEFKT5N/LkbXsaddlw6xNSXBanUYpFc2AXXpbJDilPHazcSreU/DpQIaxfX0NfQ==" }, + "node_modules/dunder-proto": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz", + "integrity": "sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A==", + "dependencies": { + "call-bind-apply-helpers": "^1.0.1", + "es-errors": "^1.3.0", + "gopd": "^1.2.0" + }, + "engines": { + "node": ">= 0.4" + } + }, "node_modules/duplexer": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/duplexer/-/duplexer-0.1.2.tgz", @@ -7342,12 +7369,9 @@ "integrity": "sha512-wd6JXUmyHmt8T5a2xreUwKcGPq6f1f+WwIJkijUqiGcJz1qqnZgP6XIK+QyIWU5lT7imeNxUll48bziG+TSYcA==" }, "node_modules/es-define-property": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.0.tgz", - "integrity": "sha512-jxayLKShrEqqzJ0eumQbVhTYQM27CfT1T35+gCgDFoL82JLsXqTJ76zv6A0YLOgEnLUMvLzsDsGIrl8NFpT2gQ==", - "dependencies": { - "get-intrinsic": "^1.2.4" - }, + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.1.tgz", + "integrity": "sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g==", "engines": { "node": ">= 0.4" } @@ -7384,14 +7408,26 @@ "resolved": "https://registry.npmjs.org/es-module-lexer/-/es-module-lexer-1.5.4.tgz", "integrity": "sha512-MVNK56NiMrOwitFB7cqDwq0CQutbw+0BvLshJSse0MUNU+y1FC3bUS/AQg7oUng+/wKrrki7JfmwtVHkVfPLlw==" }, - "node_modules/es-set-tostringtag": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/es-set-tostringtag/-/es-set-tostringtag-2.0.1.tgz", - "integrity": "sha512-g3OMbtlwY3QewlqAiMLI47KywjWZoEytKr8pf6iTC8uJq5bIAH52Z9pnQ8pVL6whrCto53JZDuUIsifGeLorTg==", + "node_modules/es-object-atoms": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/es-object-atoms/-/es-object-atoms-1.1.1.tgz", + "integrity": "sha512-FGgH2h8zKNim9ljj7dankFPcICIK9Cp5bm+c2gQSYePhpaG5+esrLODihIorn+Pe6FGJzWhXQotPv73jTaldXA==", "dependencies": { - "get-intrinsic": "^1.1.3", - "has": "^1.0.3", - "has-tostringtag": "^1.0.0" + "es-errors": "^1.3.0" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/es-set-tostringtag": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/es-set-tostringtag/-/es-set-tostringtag-2.1.0.tgz", + "integrity": "sha512-j6vWzfrGVfyXxge+O0x5sh6cvxAog0a/4Rdd2K36zCMV5eJ+/+tOAngRO8cODMNWbVRdVlmGZQL2YS3yR8bIUA==", + "dependencies": { + "es-errors": "^1.3.0", + "get-intrinsic": "^1.2.6", + "has-tostringtag": "^1.0.2", + "hasown": "^2.0.2" }, "engines": { "node": ">= 0.4" @@ -8866,13 +8902,15 @@ } }, "node_modules/form-data": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/form-data/-/form-data-3.0.1.tgz", - "integrity": "sha512-RHkBKtLWUVwd7SqRIvCZMEvAMoGUp0XU+seQiZejj0COz3RI3hWP4sCv3gZWWLjJTd7rGwcsF5eKZGii0r/hbg==", + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-3.0.4.tgz", + "integrity": "sha512-f0cRzm6dkyVYV3nPoooP8XlccPQukegwhAnpoLcXy+X+A8KfpGOoXwDr9FLZd3wzgLaBGQBE3lY93Zm/i1JvIQ==", "dependencies": { "asynckit": "^0.4.0", "combined-stream": "^1.0.8", - "mime-types": "^2.1.12" + "es-set-tostringtag": "^2.1.0", + "hasown": "^2.0.2", + "mime-types": "^2.1.35" }, "engines": { "node": ">= 6" @@ -8992,15 +9030,20 @@ } }, "node_modules/get-intrinsic": { - "version": "1.2.4", - "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.2.4.tgz", - "integrity": "sha512-5uYhsJH8VJBTv7oslg4BznJYhDoRI6waYCxMmCdnTrcCrHA/fCFKoTFz2JKKE0HdDFUF7/oQuhzumXJK7paBRQ==", + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.3.0.tgz", + "integrity": "sha512-9fSjSaos/fRIVIp+xSJlE6lfwhES7LNtKaCBIamHsjr2na1BiABJPo0mOjjz8GJDURarmCPGqaiVg5mfjb98CQ==", "dependencies": { + "call-bind-apply-helpers": "^1.0.2", + "es-define-property": "^1.0.1", "es-errors": "^1.3.0", + "es-object-atoms": "^1.1.1", "function-bind": "^1.1.2", - "has-proto": "^1.0.1", - "has-symbols": "^1.0.3", - "hasown": "^2.0.0" + "get-proto": "^1.0.1", + "gopd": "^1.2.0", + "has-symbols": "^1.1.0", + "hasown": "^2.0.2", + "math-intrinsics": "^1.1.0" }, "engines": { "node": ">= 0.4" @@ -9022,6 +9065,18 @@ "node": ">=8.0.0" } }, + "node_modules/get-proto": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/get-proto/-/get-proto-1.0.1.tgz", + "integrity": "sha512-sTSfBjoXBp89JvIKIefqw7U2CCebsc74kiY6awiGogKtoSGbgjYE/G/+l9sF3MWFPNc9IcoOC4ODfKHfxFmp0g==", + "dependencies": { + "dunder-proto": "^1.0.1", + "es-object-atoms": "^1.0.0" + }, + "engines": { + "node": ">= 0.4" + } + }, "node_modules/get-stream": { "version": "6.0.1", "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-6.0.1.tgz", @@ -9198,11 +9253,11 @@ } }, "node_modules/gopd": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.0.1.tgz", - "integrity": "sha512-d65bNlIadxvpb/A2abVdlqKqV563juRnZ1Wtk6s1sIR8uNsXR70xqIzVqxVf1eTqDunwT2MkczEeaezCKTZhwA==", - "dependencies": { - "get-intrinsic": "^1.1.3" + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.2.0.tgz", + "integrity": "sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==", + "engines": { + "node": ">= 0.4" }, "funding": { "url": "https://github.com/sponsors/ljharb" @@ -9292,9 +9347,9 @@ } }, "node_modules/has-symbols": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.3.tgz", - "integrity": "sha512-l3LCuF6MgDNwTDKkdYGEihYjt5pRPbEg46rtlmnSPlUbgmB8LOIrKJbYYFBSbnPaJexMKtiPO8hmeRjRz2Td+A==", + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.1.0.tgz", + "integrity": "sha512-1cDNdwJ2Jaohmb3sg4OmKaMBwuC48sYni5HUw2DvsC8LjGTLK9h+eb1X6RyuOHe4hT0ULCW68iomhjUoKUqlPQ==", "engines": { "node": ">= 0.4" }, @@ -9303,11 +9358,11 @@ } }, "node_modules/has-tostringtag": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/has-tostringtag/-/has-tostringtag-1.0.0.tgz", - "integrity": "sha512-kFjcSNhnlGV1kyoGk7OXKSawH5JOb/LzUc5w9B02hOTO0dfFRjbHQKvg1d6cf3HbeUmtU9VbbV3qzZ2Teh97WQ==", + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/has-tostringtag/-/has-tostringtag-1.0.2.tgz", + "integrity": "sha512-NqADB8VjPFLM2V0VvHUewwwsw0ZWBaIdgo+ieHtK3hasLz4qeCRjYcqfB6AQrBggRKppKF8L52/VqdVsO47Dlw==", "dependencies": { - "has-symbols": "^1.0.2" + "has-symbols": "^1.0.3" }, "engines": { "node": ">= 0.4" @@ -12841,6 +12896,14 @@ "tmpl": "1.0.5" } }, + "node_modules/math-intrinsics": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz", + "integrity": "sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g==", + "engines": { + "node": ">= 0.4" + } + }, "node_modules/mathjs": { "version": "14.0.1", "resolved": "https://registry.npmjs.org/mathjs/-/mathjs-14.0.1.tgz", @@ -17367,9 +17430,9 @@ "integrity": "sha512-XHjoxak8SFQnHnmYHb3PcnW5TZ+9ErLZemZei3azuIRhQLw4IExsVbL3VZJdHcLeNaXq6NqawgpDPpjBOg4B5g==" }, "node_modules/tmp": { - "version": "0.2.3", - "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.2.3.tgz", - "integrity": "sha512-nZD7m9iCPC5g0pYmcaxogYKggSfLsdxl8of3Q/oIbqCqLLIO9IAF0GWjX1z9NZRHPiXv8Wex4yDCaZsgEw0Y8w==", + "version": "0.2.4", + "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.2.4.tgz", + "integrity": "sha512-UdiSoX6ypifLmrfQ/XfiawN6hkjSBpCjhKxxZcWlUUmoXLaCKQU0bx4HF/tdDK2uzRuchf1txGvrWBzYREssoQ==", "engines": { "node": ">=14.14" } @@ -20256,12 +20319,14 @@ }, "dependencies": { "form-data": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.1.tgz", - "integrity": "sha512-tzN8e4TX8+kkxGPK8D5u0FNmjPUjw3lwC9lSLxxoB/+GtsJG91CO8bSWy73APlgAZzZbXEYZJuxjkHH2w+Ezhw==", + "version": "4.0.4", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.4.tgz", + "integrity": "sha512-KrGhL9Q4zjj0kiUt5OO4Mr/A/jlI2jDYs5eHBpYHPcBEVSiipAvn2Ko2HnPe20rmcuuvMHNdZFp+4IlGTMF0Ow==", "requires": { "asynckit": "^0.4.0", "combined-stream": "^1.0.8", + "es-set-tostringtag": "^2.1.0", + "hasown": "^2.0.2", "mime-types": "^2.1.12" } }, @@ -22700,6 +22765,15 @@ "set-function-length": "^1.2.1" } }, + "call-bind-apply-helpers": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/call-bind-apply-helpers/-/call-bind-apply-helpers-1.0.2.tgz", + "integrity": "sha512-Sp1ablJ0ivDkSzjcaJdxEunN5/XvksFJ2sMBFfq6x0ryhQV/2b/KwFe21cMpmHtPOSij8K99/wSfoEuTObmuMQ==", + "requires": { + "es-errors": "^1.3.0", + "function-bind": "^1.1.2" + } + }, "callsites": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/callsites/-/callsites-3.1.0.tgz", @@ -23831,6 +23905,16 @@ "resolved": "https://registry.npmjs.org/draco3d/-/draco3d-1.5.6.tgz", "integrity": "sha512-+3NaRjWktb5r61ZFoDejlykPEFKT5N/LkbXsaddlw6xNSXBanUYpFc2AXXpbJDilPHazcSreU/DpQIaxfX0NfQ==" }, + "dunder-proto": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz", + "integrity": "sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A==", + "requires": { + "call-bind-apply-helpers": "^1.0.1", + "es-errors": "^1.3.0", + "gopd": "^1.2.0" + } + }, "duplexer": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/duplexer/-/duplexer-0.1.2.tgz", @@ -23976,12 +24060,9 @@ "integrity": "sha512-wd6JXUmyHmt8T5a2xreUwKcGPq6f1f+WwIJkijUqiGcJz1qqnZgP6XIK+QyIWU5lT7imeNxUll48bziG+TSYcA==" }, "es-define-property": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.0.tgz", - "integrity": "sha512-jxayLKShrEqqzJ0eumQbVhTYQM27CfT1T35+gCgDFoL82JLsXqTJ76zv6A0YLOgEnLUMvLzsDsGIrl8NFpT2gQ==", - "requires": { - "get-intrinsic": "^1.2.4" - } + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.1.tgz", + "integrity": "sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g==" }, "es-errors": { "version": "1.3.0", @@ -24009,14 +24090,23 @@ "resolved": "https://registry.npmjs.org/es-module-lexer/-/es-module-lexer-1.5.4.tgz", "integrity": "sha512-MVNK56NiMrOwitFB7cqDwq0CQutbw+0BvLshJSse0MUNU+y1FC3bUS/AQg7oUng+/wKrrki7JfmwtVHkVfPLlw==" }, - "es-set-tostringtag": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/es-set-tostringtag/-/es-set-tostringtag-2.0.1.tgz", - "integrity": "sha512-g3OMbtlwY3QewlqAiMLI47KywjWZoEytKr8pf6iTC8uJq5bIAH52Z9pnQ8pVL6whrCto53JZDuUIsifGeLorTg==", + "es-object-atoms": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/es-object-atoms/-/es-object-atoms-1.1.1.tgz", + "integrity": "sha512-FGgH2h8zKNim9ljj7dankFPcICIK9Cp5bm+c2gQSYePhpaG5+esrLODihIorn+Pe6FGJzWhXQotPv73jTaldXA==", "requires": { - "get-intrinsic": "^1.1.3", - "has": "^1.0.3", - "has-tostringtag": "^1.0.0" + "es-errors": "^1.3.0" + } + }, + "es-set-tostringtag": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/es-set-tostringtag/-/es-set-tostringtag-2.1.0.tgz", + "integrity": "sha512-j6vWzfrGVfyXxge+O0x5sh6cvxAog0a/4Rdd2K36zCMV5eJ+/+tOAngRO8cODMNWbVRdVlmGZQL2YS3yR8bIUA==", + "requires": { + "es-errors": "^1.3.0", + "get-intrinsic": "^1.2.6", + "has-tostringtag": "^1.0.2", + "hasown": "^2.0.2" } }, "es-shim-unscopables": { @@ -25082,13 +25172,15 @@ } }, "form-data": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/form-data/-/form-data-3.0.1.tgz", - "integrity": "sha512-RHkBKtLWUVwd7SqRIvCZMEvAMoGUp0XU+seQiZejj0COz3RI3hWP4sCv3gZWWLjJTd7rGwcsF5eKZGii0r/hbg==", + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-3.0.4.tgz", + "integrity": "sha512-f0cRzm6dkyVYV3nPoooP8XlccPQukegwhAnpoLcXy+X+A8KfpGOoXwDr9FLZd3wzgLaBGQBE3lY93Zm/i1JvIQ==", "requires": { "asynckit": "^0.4.0", "combined-stream": "^1.0.8", - "mime-types": "^2.1.12" + "es-set-tostringtag": "^2.1.0", + "hasown": "^2.0.2", + "mime-types": "^2.1.35" } }, "forwarded": { @@ -25164,15 +25256,20 @@ "integrity": "sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==" }, "get-intrinsic": { - "version": "1.2.4", - "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.2.4.tgz", - "integrity": "sha512-5uYhsJH8VJBTv7oslg4BznJYhDoRI6waYCxMmCdnTrcCrHA/fCFKoTFz2JKKE0HdDFUF7/oQuhzumXJK7paBRQ==", + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.3.0.tgz", + "integrity": "sha512-9fSjSaos/fRIVIp+xSJlE6lfwhES7LNtKaCBIamHsjr2na1BiABJPo0mOjjz8GJDURarmCPGqaiVg5mfjb98CQ==", "requires": { + "call-bind-apply-helpers": "^1.0.2", + "es-define-property": "^1.0.1", "es-errors": "^1.3.0", + "es-object-atoms": "^1.1.1", "function-bind": "^1.1.2", - "has-proto": "^1.0.1", - "has-symbols": "^1.0.3", - "hasown": "^2.0.0" + "get-proto": "^1.0.1", + "gopd": "^1.2.0", + "has-symbols": "^1.1.0", + "hasown": "^2.0.2", + "math-intrinsics": "^1.1.0" } }, "get-own-enumerable-property-symbols": { @@ -25185,6 +25282,15 @@ "resolved": "https://registry.npmjs.org/get-package-type/-/get-package-type-0.1.0.tgz", "integrity": "sha512-pjzuKtY64GYfWizNAJ0fr9VqttZkNiK2iS430LtIHzjBEr6bX8Am2zm4sW4Ro5wjWW5cAlRL1qAMTcXbjNAO2Q==" }, + "get-proto": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/get-proto/-/get-proto-1.0.1.tgz", + "integrity": "sha512-sTSfBjoXBp89JvIKIefqw7U2CCebsc74kiY6awiGogKtoSGbgjYE/G/+l9sF3MWFPNc9IcoOC4ODfKHfxFmp0g==", + "requires": { + "dunder-proto": "^1.0.1", + "es-object-atoms": "^1.0.0" + } + }, "get-stream": { "version": "6.0.1", "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-6.0.1.tgz", @@ -25311,12 +25417,9 @@ } }, "gopd": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.0.1.tgz", - "integrity": "sha512-d65bNlIadxvpb/A2abVdlqKqV563juRnZ1Wtk6s1sIR8uNsXR70xqIzVqxVf1eTqDunwT2MkczEeaezCKTZhwA==", - "requires": { - "get-intrinsic": "^1.1.3" - } + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.2.0.tgz", + "integrity": "sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==" }, "graceful-fs": { "version": "4.2.11", @@ -25378,16 +25481,16 @@ "integrity": "sha512-7qE+iP+O+bgF9clE5+UoBFzE65mlBiVj3tKCrlNQ0Ogwm0BjpT/gK4SlLYDMybDh5I3TCTKnPPa0oMG7JDYrhg==" }, "has-symbols": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.3.tgz", - "integrity": "sha512-l3LCuF6MgDNwTDKkdYGEihYjt5pRPbEg46rtlmnSPlUbgmB8LOIrKJbYYFBSbnPaJexMKtiPO8hmeRjRz2Td+A==" + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.1.0.tgz", + "integrity": "sha512-1cDNdwJ2Jaohmb3sg4OmKaMBwuC48sYni5HUw2DvsC8LjGTLK9h+eb1X6RyuOHe4hT0ULCW68iomhjUoKUqlPQ==" }, "has-tostringtag": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/has-tostringtag/-/has-tostringtag-1.0.0.tgz", - "integrity": "sha512-kFjcSNhnlGV1kyoGk7OXKSawH5JOb/LzUc5w9B02hOTO0dfFRjbHQKvg1d6cf3HbeUmtU9VbbV3qzZ2Teh97WQ==", + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/has-tostringtag/-/has-tostringtag-1.0.2.tgz", + "integrity": "sha512-NqADB8VjPFLM2V0VvHUewwwsw0ZWBaIdgo+ieHtK3hasLz4qeCRjYcqfB6AQrBggRKppKF8L52/VqdVsO47Dlw==", "requires": { - "has-symbols": "^1.0.2" + "has-symbols": "^1.0.3" } }, "hasown": { @@ -27942,6 +28045,11 @@ "tmpl": "1.0.5" } }, + "math-intrinsics": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz", + "integrity": "sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g==" + }, "mathjs": { "version": "14.0.1", "resolved": "https://registry.npmjs.org/mathjs/-/mathjs-14.0.1.tgz", @@ -31052,9 +31160,9 @@ "integrity": "sha512-XHjoxak8SFQnHnmYHb3PcnW5TZ+9ErLZemZei3azuIRhQLw4IExsVbL3VZJdHcLeNaXq6NqawgpDPpjBOg4B5g==" }, "tmp": { - "version": "0.2.3", - "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.2.3.tgz", - "integrity": "sha512-nZD7m9iCPC5g0pYmcaxogYKggSfLsdxl8of3Q/oIbqCqLLIO9IAF0GWjX1z9NZRHPiXv8Wex4yDCaZsgEw0Y8w==" + "version": "0.2.4", + "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.2.4.tgz", + "integrity": "sha512-UdiSoX6ypifLmrfQ/XfiawN6hkjSBpCjhKxxZcWlUUmoXLaCKQU0bx4HF/tdDK2uzRuchf1txGvrWBzYREssoQ==" }, "tmpl": { "version": "1.0.5", diff --git a/app/src/Events.js b/app/src/Events.js index 29a35412..300db707 100644 --- a/app/src/Events.js +++ b/app/src/Events.js @@ -101,6 +101,10 @@ function handleEvents(events) { () => window.open(url, '_self')); } + if (event === 'upload_archive_failed') { + eventToast('Archive Upload Failed!', message, 'error', 5000); + } + if (subject) { newestEvents[subject] = dt; } diff --git a/app/src/components/Download.js b/app/src/components/Download.js index e045fa84..5ce4de7d 100644 --- a/app/src/components/Download.js +++ b/app/src/components/Download.js @@ -271,8 +271,13 @@ function VideoDownloadCountLimit({form, name = 'video_count_limit', path = 'sett /> } -export function VideoResolutionSelectorForm({form, name = 'video_resolutions', path = 'settings.video_resolutions'}) { - const [inputProps, inputAttrs] = form.getSelectionProps({name, path, type: 'array'}); +export function VideoResolutionSelectorForm({form, name = 'video_resolutions', path = 'settings.video_resolutions', onChange}) { + const [inputProps, inputAttrs] = form.getSelectionProps({ + name, + path, + type: 'array', + afterChange: onChange + }); return <> } -export function VideosDownloadForm({singleDownload = true, onCancel}) { +export function VideosDownloadForm({singleDownload = true, onCancel, onSuccess: propOnSuccess, download, submitter: propSubmitter, actions}) { const [showMessage, setShowMessage] = React.useState(false); + const [userChangedResolutions, setUserChangedResolutions] = React.useState(false); + const [config, setConfig] = React.useState(null); - // Keep video settings in session to help user start downloads consistently. - const [defaultVideoResolutions, setDefaultVideoResolutions] = useLocalStorage('video_resolutions', defaultVideoResolutionOptions); + // Keep video format in session to help user start downloads consistently. const [defaultVideoFormat, setDefaultVideoFormat] = useLocalStorage('video_format', defaultVideoFormatOption); + // Use config video resolutions if available, otherwise use default + const configResolutions = config && config.video_resolutions ? config.video_resolutions : defaultVideoResolutionOptions; + const defaultFormData = { urls: '', // Textarea, one URL per line. destination: '', @@ -397,11 +406,11 @@ export function VideosDownloadForm({singleDownload = true, onCancel}) { settings: { use_browser_profile: false, video_format: defaultVideoFormat, - video_resolutions: defaultVideoResolutions, + video_resolutions: configResolutions, } } - const submitter = async (formData) => { + const submitter = propSubmitter || (async (formData) => { const downloadData = { destination: formData.destination, downloader: formData.downloader, @@ -410,24 +419,45 @@ export function VideosDownloadForm({singleDownload = true, onCancel}) { urls: formData.urls.split(/r?\n/), } await postDownload(downloadData); - } + }); const onSuccess = () => { setShowMessage(true); - form.reset(); + if (propOnSuccess) { + propOnSuccess(); + } else { + form.reset(); + } } const form = useForm({ submitter, - defaultFormData, + defaultFormData: download ? mergeDeep(defaultFormData, download) : defaultFormData, onSuccess, }); + // Fetch video downloader config when the modal opens React.useEffect(() => { - const {video_resolutions, video_format} = form.formData.settings; - if (video_resolutions && video_resolutions !== defaultVideoResolutions) { - setDefaultVideoResolutions(video_resolutions); - } + const fetchConfig = async () => { + try { + const result = await fetchVideoDownloaderConfig(); + setConfig(result); + + // Update form with video resolutions from config only if user hasn't changed them + // and if no download object was provided (this is a new download, not an edit) + if (result && result.video_resolutions && !userChangedResolutions && !download) { + form.setValue('settings.video_resolutions', result.video_resolutions); + } + } catch (error) { + console.error('Failed to fetch video downloader config:', error); + } + }; + + fetchConfig(); + }, []); + + React.useEffect(() => { + const {video_format} = form.formData.settings; if (video_format && video_format !== defaultVideoFormat) { setDefaultVideoFormat(video_format); } @@ -473,7 +503,10 @@ export function VideosDownloadForm({singleDownload = true, onCancel}) { - + setUserChangedResolutions(true)} + /> @@ -492,7 +525,7 @@ export function VideosDownloadForm({singleDownload = true, onCancel}) { {showMessage && } - + {actions ? actions({onCancel: localOnCancel, form}) : } @@ -511,6 +544,40 @@ export function VideoMinimumDurationForm({form}) { /> } +export function EditVideosDownloadForm({ + download, + onCancel, + onSuccess, + onDelete, + actions = EditDownloadFormButtons, +}) { + const submitter = async (formData) => { + // Create a copy of settings without channel_url and channel_id + const settings = {...formData.settings}; + // These settings are created when downloading the video, we can't submit them again. + delete settings.channel_url; + delete settings.channel_id; + + const downloadData = { + destination: formData.destination, + downloader: formData.downloader, + settings: settings, + tag_names: formData.tag_names, + urls: formData.urls.split(/r?\n/), + } + await putDownload(download.id, downloadData); + } + + return actions({...props, onDelete})} + /> +} + export function VideoMaximumDurationForm({form}) { return { @@ -557,10 +627,12 @@ export function ChannelDownloadForm({ } } - // Keep video settings in session to help user start downloads consistently. - const [defaultVideoResolutions, setDefaultVideoResolutions] = useLocalStorage('video_resolutions', defaultVideoResolutionOptions); + // Keep video format in session to help user start downloads consistently. const [defaultVideoFormat, setDefaultVideoFormat] = useLocalStorage('video_format', defaultVideoFormatOption); + // Use config video resolutions if available, otherwise use default + const configResolutions = config && config.video_resolutions ? config.video_resolutions : defaultVideoResolutionOptions; + const emptyFormData = { destination: '', downloader: Downloaders.VideoChannel, @@ -577,7 +649,7 @@ export function ChannelDownloadForm({ use_browser_profile: false, video_count_limit: null, video_format: defaultVideoFormat, - video_resolutions: defaultVideoResolutions, + video_resolutions: configResolutions, }, sub_downloader: Downloaders.Video, tag_names: [], @@ -591,11 +663,30 @@ export function ChannelDownloadForm({ clearOnSuccess, }); + // Fetch video downloader config when the modal opens React.useEffect(() => { - const {video_resolutions, video_format} = form.formData.settings; - if (video_resolutions && video_resolutions !== defaultVideoResolutions) { - setDefaultVideoResolutions(video_resolutions); - } + const fetchConfig = async () => { + try { + const result = await fetchVideoDownloaderConfig(); + setConfig(result); + setIsConfigLoaded(true); + + // Update form with video resolutions from config only if user hasn't changed them + // and if no download object was provided (this is a new download, not an edit) + if (result && result.video_resolutions && !userChangedResolutions && !download) { + form.setValue('settings.video_resolutions', result.video_resolutions); + } + } catch (error) { + console.error('Failed to fetch video downloader config:', error); + setIsConfigLoaded(true); + } + }; + + fetchConfig(); + }, []); + + React.useEffect(() => { + const {video_format} = form.formData.settings; if (video_format && video_format !== defaultVideoFormat) { setDefaultVideoFormat(video_format); } @@ -656,7 +747,10 @@ export function ChannelDownloadForm({ - + setUserChangedResolutions(true)} + /> @@ -730,17 +824,42 @@ function SuccessfulDownloadSubmitMessage() { } -export function ArchiveDownloadForm({download, onCancel}) { - const [showMessage, setShowMessage] = React.useState(false); - +export function EditArchiveDownloadForm({ + download, + onCancel, + onSuccess, + onDelete, + actions = EditDownloadFormButtons, +}) { const submitter = async (formData) => { + const downloadData = { + downloader: formData.downloader, + tag_names: formData.tag_names, + urls: formData.urls.split(/\r?\n/), + } + await putDownload(download.id, downloadData); + } + + return actions({...props, onDelete})} + /> +} + +export function ArchiveDownloadForm({download, onCancel, onSuccess: propOnSuccess, submitter: propSubmitter, actions}) { + const [showMessage, setShowMessage] = React.useState(false); + + const submitter = propSubmitter || (async (formData) => { const downloadData = { downloader: formData.downloader, tag_names: formData.tag_names, urls: formData.urls.split(/\r?\n/), } await postDownload(downloadData); - }; + }); const emptyFormData = { downloader: Downloaders.Archive, @@ -748,14 +867,28 @@ export function ArchiveDownloadForm({download, onCancel}) { tag_names: [], }; + const onSuccess = () => { + setShowMessage(true); + if (propOnSuccess) { + propOnSuccess(); + } + } + const form = useForm({ submitter, defaultFormData: mergeDeep(emptyFormData, download), emptyFormData, - clearOnSuccess: true, - onSuccess: async () => setShowMessage(true), + clearOnSuccess: !propOnSuccess, + onSuccess, }); + const localOnCancel = (e) => { + if (e) e.preventDefault(); + if (onCancel) { + onCancel(); + } + } + return
Archives

Create a Singlefile Archive for each of the URLs provided below.

@@ -774,7 +907,7 @@ export function ArchiveDownloadForm({download, onCancel}) { {showMessage && } - + {actions ? actions({onCancel: localOnCancel, form}) : } @@ -783,8 +916,10 @@ export function ArchiveDownloadForm({download, onCancel}) { export function RSSDownloadForm({download, submitter, onDelete, onCancel, actions, clearOnSuccess = true}) { const [showMessage, setShowMessage] = React.useState(false); + const [config, setConfig] = React.useState(null); + const [isConfigLoaded, setIsConfigLoaded] = React.useState(false); + const [userChangedResolutions, setUserChangedResolutions] = React.useState(false); - const [defaultVideoResolutions, setDefaultVideoResolutions] = useLocalStorage('video_resolutions', defaultVideoResolutionOptions); const [defaultVideoFormat, setDefaultVideoFormat] = useLocalStorage('video_format', defaultVideoFormatOption); submitter = submitter || (async (formData) => { @@ -800,6 +935,9 @@ export function RSSDownloadForm({download, submitter, onDelete, onCancel, action await postDownload(downloadData); }); + // Use config video resolutions if available, otherwise use default + const configResolutions = config && config.video_resolutions ? config.video_resolutions : defaultVideoResolutionOptions; + const emptyFormData = { destination: null, downloader: Downloaders.RSS, @@ -809,7 +947,7 @@ export function RSSDownloadForm({download, submitter, onDelete, onCancel, action excluded_urls: null, title_exclude: null, title_include: null, - video_resolutions: defaultVideoResolutions, + video_resolutions: configResolutions, video_format: defaultVideoFormat, }, tag_names: [], @@ -824,11 +962,30 @@ export function RSSDownloadForm({download, submitter, onDelete, onCancel, action onSuccess: async () => setShowMessage(true), }); + // Fetch video downloader config when the modal opens React.useEffect(() => { - const {video_resolutions, video_format} = form.formData.settings; - if (video_resolutions && video_resolutions !== defaultVideoResolutions) { - setDefaultVideoResolutions(video_resolutions); - } + const fetchConfig = async () => { + try { + const result = await fetchVideoDownloaderConfig(); + setConfig(result); + setIsConfigLoaded(true); + + // Update form with video resolutions from config only if user hasn't changed them + // and if no download object was provided (this is a new download, not an edit) + if (result && result.video_resolutions && !userChangedResolutions && !download) { + form.setValue('settings.video_resolutions', result.video_resolutions); + } + } catch (error) { + console.error('Failed to fetch video downloader config:', error); + setIsConfigLoaded(true); + } + }; + + fetchConfig(); + }, []); + + React.useEffect(() => { + const {video_format} = form.formData.settings; if (video_format && video_format !== defaultVideoFormat) { setDefaultVideoFormat(video_format); } @@ -859,7 +1016,10 @@ export function RSSDownloadForm({download, submitter, onDelete, onCancel, action - + setUserChangedResolutions(true)} + /> diff --git a/app/src/components/FilePreview.js b/app/src/components/FilePreview.js index e49d3b51..c276e92b 100644 --- a/app/src/components/FilePreview.js +++ b/app/src/components/FilePreview.js @@ -193,6 +193,11 @@ export function FilePreviewProvider({children}) { // Navigated to a page which has a file preview active, fetch the information about the file, then display it. if (previewQuery && !previewFile) { initPreviewFile(); + } else if (!previewQuery && (previewFile || previewModal)) { + // User navigated back/forward and preview query is gone, close the preview. + // Only close if there's actually a preview open (previewFile or previewModal exists). + setPreviewFile(null); + setPreviewModal(null); } }, [previewQuery]); diff --git a/app/src/components/Search.js b/app/src/components/Search.js index 0281c08b..59e9fb10 100644 --- a/app/src/components/Search.js +++ b/app/src/components/Search.js @@ -208,6 +208,10 @@ export function useSearchSuggestions(defaultSearchStr, defaultTagNames, anyTag) // The results summarized. const [suggestionsSums, setSuggestionsSums] = useState({}); + // Disable selecting a result briefly after new suggestions arrive. + const [selectDisabled, setSelectDisabled] = React.useState(false); + const selectDisableTimerRef = React.useRef(null); + const noResults = [{title: 'No results'}]; const normalizeSuggestionsResults = (newSuggestions) => { @@ -303,17 +307,40 @@ export function useSearchSuggestions(defaultSearchStr, defaultTagNames, anyTag) }); } + const suggestionSelectDelay = 250; + React.useEffect(() => { setSuggestionsSums({}); setSuggestionsResults({}); if (!_.isEmpty(suggestions)) { + // Start a brief window where selecting results is disabled to prevent accidental clicks + // when the dropdown re-renders with new suggestions. + if (selectDisableTimerRef.current) { + clearTimeout(selectDisableTimerRef.current); + } + setSelectDisabled(true); + selectDisableTimerRef.current = setTimeout(() => setSelectDisabled(false), suggestionSelectDelay); + normalizeSuggestionsResults(suggestions); } }, [JSON.stringify(suggestions)]); + // Clear timer on unmount. + React.useEffect(() => { + return () => { + if (selectDisableTimerRef.current) { + clearTimeout(selectDisableTimerRef.current); + } + }; + }, []); + // User clicked on a result in the dropdown. const handleResultSelect = ({result}) => { + if (selectDisabled) { + console.debug('Selection temporarily disabled after suggestions update'); + return; + } if (result.location) { console.info(`useSearchSuggestions Navigating: ${result.location}`) navigate(result.location); diff --git a/app/src/components/Videos.js b/app/src/components/Videos.js index cd594f3a..c2145e6a 100644 --- a/app/src/components/Videos.js +++ b/app/src/components/Videos.js @@ -93,6 +93,7 @@ function VideosPage() { {value: 'published_datetime', text: 'Published Date', short: 'P.Date'}, {value: 'length', text: 'Length'}, {value: 'size', text: 'Size'}, + {value: 'size_to_duration', text: 'Size to Duration', short: 'S/Duration'}, {value: 'view_count', text: 'Views'}, {value: 'viewed', text: 'Recently Viewed', short: 'R.Viewed'}, {value: 'download_datetime', text: 'Download Date', short: 'D.Date'}, diff --git a/app/src/components/admin/Downloads.js b/app/src/components/admin/Downloads.js index 9723eab3..6bee85c4 100644 --- a/app/src/components/admin/Downloads.js +++ b/app/src/components/admin/Downloads.js @@ -18,7 +18,7 @@ import { WROLModeMessage } from "../Common"; import { - Button as SButton, + Button as SButton, ButtonGroup, Label, Loader, PlaceholderLine, @@ -35,7 +35,9 @@ import { EditChannelDownloadForm, EditRSSDownloadForm, EditScrapeFilesDownloadForm, - EditZimDownloadForm + EditZimDownloadForm, + EditVideosDownloadForm, + EditArchiveDownloadForm } from "../Download"; import {Downloaders} from "../Vars"; @@ -246,6 +248,9 @@ function RecurringDownloadRow({download, fetchDownloads, onDelete}) { class OnceDownloadRow extends React.Component { constructor(props) { super(props); + this.state = { + editModalOpen: false + }; } handleDelete = async () => { @@ -272,8 +277,21 @@ class OnceDownloadRow extends React.Component { } }; + handleEditOpen = () => { + this.setState({ editModalOpen: true }); + }; + + handleEditClose = () => { + this.setState({ editModalOpen: false }); + }; + + handleEditSuccess = async () => { + await this.props.fetchDownloads(); + this.handleEditClose(); + }; + render() { - let {url, last_successful_download, status, location, error} = this.props; + let {url, last_successful_download, status, location, error, downloader, settings, id} = this.props; // Open downloads (/download), or external links in an anchor. const link = location && !location.startsWith('/download') ? @@ -297,6 +315,8 @@ class OnceDownloadRow extends React.Component { } else if (status === 'failed' || status === 'deferred') { buttonCell = ( + + + {(downloader === Downloaders.Video || downloader === Downloaders.Archive) && status !== 'pending' && ( +