Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
rescheduled 🗓️
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Analyze
Contributor analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
c3lingo
rescheduled 🗓️
Commits
b37ec0db
"git@git.cccv.de:chaos-parcel-service/bgp_worker.git" did not exist on "8005f2d6f7c1891173572c4c71318f3ec859f243"
Verified
Commit
b37ec0db
authored
4 months ago
by
tribut
Browse files
Options
Downloads
Patches
Plain Diff
Switch to new single-request API for filedrop
parent
609907e9
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
app/jobs/pretalx/import_job.rb
+7
-30
7 additions, 30 deletions
app/jobs/pretalx/import_job.rb
with
7 additions
and
30 deletions
app/jobs/pretalx/import_job.rb
+
7
−
30
View file @
b37ec0db
...
@@ -62,7 +62,7 @@ module Pretalx
...
@@ -62,7 +62,7 @@ module Pretalx
end
end
end
end
session
.
recorded
=
!
session_data
.
fetch
(
'do_not_record'
,
false
)
session
.
recorded
=
!
session_data
.
fetch
(
'do_not_record'
,
false
)
update_filedrop_data
(
session
,
filedrop_config
)
if
filedrop_index
[
session
.
ref_id
]
update_filedrop_data
(
session
,
filedrop_index
[
session
.
ref_id
],
filedrop_config
)
if
filedrop_index
[
session
.
ref_id
]
session
.
save!
session
.
save!
end
end
end
end
...
@@ -95,7 +95,7 @@ module Pretalx
...
@@ -95,7 +95,7 @@ module Pretalx
username:
fetch_credential
(
"filedrop_user"
),
username:
fetch_credential
(
"filedrop_user"
),
password:
fetch_credential
(
"filedrop_password"
)
},
password:
fetch_credential
(
"filedrop_password"
)
},
headers:
{
'Accept'
=>
'application/json'
},
headers:
{
'Accept'
=>
'application/json'
},
timeout:
5
timeout:
30
)
)
data
=
JSON
.
parse
(
response
.
body
)
data
=
JSON
.
parse
(
response
.
body
)
rescue
=>
e
rescue
=>
e
...
@@ -112,32 +112,9 @@ module Pretalx
...
@@ -112,32 +112,9 @@ module Pretalx
end
end
end
end
def
update_filedrop_data
(
session
,
filedrop_config
)
def
update_filedrop_data
(
session
,
filedrop_data
,
filedrop_config
)
if
!
filedrop_config
||
!
filedrop_config
[
'url'
]
return
{}
end
response
=
HTTParty
.
get
(
filedrop_config
[
'url'
]
+
"/talks/"
+
session
.
ref_id
,
basic_auth:
{
username:
fetch_credential
(
"filedrop_user"
),
password:
fetch_credential
(
"filedrop_password"
)
},
headers:
{
'Accept'
=>
'application/json'
}
)
begin
data
=
JSON
.
parse
(
response
.
body
)
rescue
=>
e
Rails
.
logger
.
warn
(
"Filedrop response could not be parsed:
#{
e
.
message
}
"
)
return
{}
end
if
!
data
[
"files"
].
is_a?
(
Array
)
||
!
data
[
"comments"
].
is_a?
(
Array
)
Rails
.
logger
.
warn
(
"Filedrop info for
#{
session
.
ref_id
}
was incomplete"
)
return
{}
end
existing_comments
=
session
.
filedrop_comments
.
pluck
(
:body
)
existing_comments
=
session
.
filedrop_comments
.
pluck
(
:body
)
new_comments
=
data
[
"comments"
]
&
.
pluck
(
"body"
)
||
[]
new_comments
=
filedrop_
data
[
"comments"
]
&
.
pluck
(
"body"
)
||
[]
# Remove comments not in the JSON file
# Remove comments not in the JSON file
(
existing_comments
-
new_comments
).
each
do
|
body
|
(
existing_comments
-
new_comments
).
each
do
|
body
|
...
@@ -145,7 +122,7 @@ module Pretalx
...
@@ -145,7 +122,7 @@ module Pretalx
end
end
# Add or update comments
# Add or update comments
data
[
"comments"
]
&
.
each
do
|
comment_data
|
filedrop_
data
[
"comments"
]
&
.
each
do
|
comment_data
|
session
.
filedrop_comments
.
find_or_initialize_by
(
body:
comment_data
[
'body'
]).
tap
do
|
comment
|
session
.
filedrop_comments
.
find_or_initialize_by
(
body:
comment_data
[
'body'
]).
tap
do
|
comment
|
comment
.
orig_created
=
parse_datetime_or_nil
(
comment_data
[
'meta'
][
'created'
])
comment
.
orig_created
=
parse_datetime_or_nil
(
comment_data
[
'meta'
][
'created'
])
comment
.
save!
comment
.
save!
...
@@ -153,7 +130,7 @@ module Pretalx
...
@@ -153,7 +130,7 @@ module Pretalx
end
end
existing_files
=
session
.
filedrop_files
.
pluck
(
:name
,
:checksum
)
existing_files
=
session
.
filedrop_files
.
pluck
(
:name
,
:checksum
)
new_files
=
data
[
'files'
]
&
.
map
{
|
d
|
[
d
[
'name'
],
d
.
dig
(
'meta'
,
'hash'
)]
}
||
[]
new_files
=
filedrop_
data
[
'files'
]
&
.
map
{
|
d
|
[
d
[
'name'
],
d
.
dig
(
'meta'
,
'hash'
)]
}
||
[]
# Remove files not in the JSON file
# Remove files not in the JSON file
(
existing_files
-
new_files
).
each
do
|
name
,
checksum
|
(
existing_files
-
new_files
).
each
do
|
name
,
checksum
|
...
@@ -161,7 +138,7 @@ module Pretalx
...
@@ -161,7 +138,7 @@ module Pretalx
end
end
# Add or update files
# Add or update files
data
[
'files'
]
&
.
each
do
|
file_data
|
filedrop_
data
[
'files'
]
&
.
each
do
|
file_data
|
session
.
filedrop_files
.
find_or_initialize_by
(
name:
file_data
[
'name'
],
checksum:
file_data
[
'meta'
][
'hash'
]).
tap
do
|
file
|
session
.
filedrop_files
.
find_or_initialize_by
(
name:
file_data
[
'name'
],
checksum:
file_data
[
'meta'
][
'hash'
]).
tap
do
|
file
|
file
.
size
=
file_data
[
'meta'
][
'size'
]
file
.
size
=
file_data
[
'meta'
][
'size'
]
file
.
orig_created
=
parse_datetime_or_nil
(
file_data
[
'meta'
][
'created'
])
file
.
orig_created
=
parse_datetime_or_nil
(
file_data
[
'meta'
][
'created'
])
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment