-
-
Notifications
You must be signed in to change notification settings - Fork 237
0.30.11 #1676
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
0.30.11 #1676
Changes from 6 commits
b049c11
edb9287
432e1d2
5a85a56
b9ab38e
6491d04
a6f4a93
d400d3c
625b8e6
86bfe1b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,7 +21,7 @@ class Import < ApplicationRecord | |
| google_semantic_history: 0, owntracks: 1, google_records: 2, | ||
| google_phone_takeout: 3, gpx: 4, immich_api: 5, geojson: 6, photoprism_api: 7, | ||
| user_data_archive: 8 | ||
| } | ||
| }, allow_nil: true | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainEnum now allows nil; verify downstream assumptions and queries Allowing
Run this quick scan to find potential assumptions: 🏁 Script executed: #!/bin/bash
# Find validations or code paths that assume presence of `source`
rg -n -C2 --type ruby '\bvalidates\s+:source|\bsource\.\w+\?|where\([^)]*source:|\bgroup\(:source\)|pluck\(:source\)' -g '!**/spec/**'
# Find places that compare or branch on source without nil guards
rg -n -C2 --type ruby '\bif\s+.*source\b|\bcase\s+.*source\b'Length of output: 2961 Handle nil The
These code paths must be updated to either guard against 🤖 Prompt for AI Agents |
||
|
|
||
| def process! | ||
| if user_data_archive? | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -16,7 +16,13 @@ def call | |||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| temp_file_path = Imports::SecureFileDownloader.new(import.file).download_to_temp_file | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| source = import.source.presence || detect_source_from_file(temp_file_path) | ||||||||||||||||||||||||||||||||||||
| source = if import.source.nil? || should_detect_source? | ||||||||||||||||||||||||||||||||||||
| detect_source_from_file(temp_file_path) | ||||||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||||||
| import.source | ||||||||||||||||||||||||||||||||||||
| end | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| import.update!(source: source) | ||||||||||||||||||||||||||||||||||||
|
Comment on lines
+19
to
+25
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainAvoid overriding explicit sources and lazily download only when detection is needed.
Replace this block to defer downloading until needed and not override when detection is skipped: - source = if import.source.nil? || should_detect_source?
- detect_source_from_file(temp_file_path)
- else
- import.source
- end
-
- import.update!(source: source)
+ source = import.source
+ temp_file_path = nil
+ if source.nil? || should_detect_source?
+ temp_file_path = Imports::SecureFileDownloader.new(import.file).download_to_temp_file
+ source = detect_source_from_file(temp_file_path)
+ end
+ import.update!(source: source)Note: With this change you should remove the unconditional download earlier in the method (Line 17) so the file is not fetched for API imports. Please verify 🏁 Script executed: #!/bin/bash
# Locate Photos::Importer initializer to confirm file arg is optional or unused.
rg -nP --type rb -C3 'class\s+Photos::Importer\b|def\s+initialize\(' appLength of output: 101 🏁 Script executed: #!/bin/bash
# Locate Photos::Importer class definition
rg -n 'class Photos::Importer' -g '*.rb' app
# Inspect the initialize method signature in that file
rg -n -C3 'def initialize' -g '*.rb' appLength of output: 46105 Defer file download and preserve explicit sources The current implementation always downloads the import file before checking if source detection is needed and may overwrite an explicitly set • Only download when detection is required (i.e., when Locations to update:
Proposed diff: - # existing unconditional download at Line 17 – remove this:
- temp_file_path = Imports::SecureFileDownloader.new(import.file).download_to_temp_file
-
- source = if import.source.nil? || should_detect_source?
- detect_source_from_file(temp_file_path)
- else
- import.source
- end
-
- import.update!(source: source)
+ source = import.source
+ temp_file_path = nil
+
+ if source.nil? || should_detect_source?
+ # Only download when we need to detect
+ temp_file_path = Imports::SecureFileDownloader.new(import.file).download_to_temp_file
+ source = detect_source_from_file(temp_file_path)
+ end
+
+ import.update!(source: source)📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||
| importer(source).new(import, user.id, temp_file_path).call | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| schedule_stats_creating(user.id) | ||||||||||||||||||||||||||||||||||||
|
|
@@ -90,8 +96,14 @@ def create_import_failed_notification(import, user, error) | |||||||||||||||||||||||||||||||||||
| ).call | ||||||||||||||||||||||||||||||||||||
| end | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| def should_detect_source? | ||||||||||||||||||||||||||||||||||||
| # Don't override API-based sources that can't be reliably detected | ||||||||||||||||||||||||||||||||||||
| !%w[immich_api photoprism_api].include?(import.source) | ||||||||||||||||||||||||||||||||||||
| end | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| def detect_source_from_file(temp_file_path) | ||||||||||||||||||||||||||||||||||||
| detector = Imports::SourceDetector.new_from_file_header(temp_file_path) | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| detector.detect_source! | ||||||||||||||||||||||||||||||||||||
| end | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| class RemoveDefaultFromImportsSource < ActiveRecord::Migration[8.0] | ||
| def change | ||
| change_column_default :imports, :source, from: 0, to: nil | ||
| end | ||
| end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,3 @@ | ||
| // This file contains 3 doubles | ||
|
|
||
| { | ||
| "semanticSegments": [ | ||
| { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Verification agent
❓ Verification inconclusive
Strengthen uniqueness: second-level timestamp can collide; also trim trailing whitespace
If a user uploads multiple files with the same original name within the same second, both will receive the same timestamped name, causing collisions. Use microseconds and re-check in a loop (or add a short counter suffix) to guarantee uniqueness. Also, RuboCop flagged trailing whitespace (Line 120/121).
Apply this diff to harden uniqueness and remove trailing spaces:
If there’s a unique DB index on
imports.name, we’re covered at the database layer too. Check with:🏁 Script executed:
Length of output: 81
🏁 Script executed:
Length of output: 313
Ensure true name uniqueness and clean up whitespace
I didn’t find a unique database index on
imports.name, so name collisions could still occur if two imports are created within the same microsecond. Please:imports.nameat the database level (e.g. via a Rails migration) to enforce this constraint.Apply these changes:
And add a migration such as:
This combination guarantees both application-level and database-level uniqueness.
🧰 Tools
🪛 RuboCop (1.76.1)
[convention] 120-120: Trailing whitespace detected.
(Layout/TrailingWhitespace)
🤖 Prompt for AI Agents