5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-10-07 15:16:55 +00:00

Merge branch 'issue-9361' into panel.sutty.nl
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
f 2023-03-25 15:56:27 -03:00
commit 82f51c02b1
2 changed files with 15 additions and 8 deletions

View file

@ -24,7 +24,7 @@ module ActiveStorage
instrument :upload, key: key, checksum: checksum do
unless exist?(key)
IO.copy_stream(io, make_path_for(key))
LfsObjectService.new(site: site, usuarie: current_usuarie, blob: blob).process
LfsObjectService.new(site: site, blob: blob_for(key)).process
end
ensure_integrity_of(key, checksum) if checksum
end
@ -77,7 +77,7 @@ module ActiveStorage
# @param :key [String]
# @return [String]
def filename_for(key)
ActiveStorage::Blob.where(key: key).limit(1).pluck(:filename).first.tap do |filename|
blob_for(key).filename.to_s.tap do |filename|
raise ArgumentError, "Filename for key #{key} is blank" if filename.blank?
end
end
@ -92,7 +92,11 @@ module ActiveStorage
# @return [Site]
def site
@site ||= Site.find_by_name(File.basename(root))
@site ||= Site.find_by_name(name)
end
def blob_for(key)
ActiveStorage::Blob.find_by(key: key, service_name: name)
end
end
end

View file

@ -2,14 +2,13 @@
# Representa un objeto git LFS
class LfsObjectService
attr_reader :site, :blob, :usuarie
attr_reader :site, :blob
# @param :site [Site]
# @param :blob [ActiveStorage::Blob]
def initialize(site:, blob:, usuarie:)
def initialize(site:, blob:)
@site = site
@blob = blob
@usuarie = usuarie
end
def process
@ -23,7 +22,7 @@ class LfsObjectService
Site::Writer.new(site: site, file: path, content: pointer).save
# Commitear el pointer
site.repository.commit(file: path, usuarie: usuarie, message: File.basename(path))
site.repository.commit(file: path, usuarie: author, message: File.basename(path))
# Eliminar el pointer
FileUtils.rm(path)
@ -44,7 +43,7 @@ class LfsObjectService
# @return [String]
def object_path
@git_lfs_object_path ||= File.join(site.path, '.git', 'lfs', 'objects', digest[0..1], digest[2..3], digest)
@object_path ||= File.join(site.path, '.git', 'lfs', 'objects', digest[0..1], digest[2..3], digest)
end
# @return [Integer]
@ -61,4 +60,8 @@ class LfsObjectService
size #{size}
POINTER
end
def author
@author ||= GitAuthor.new email: "disk_service@#{Site.domain}", name: 'DiskService'
end
end