mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-27 21:16:22 +00:00
Merge branch 'jekyll-service' into panel.sutty.nl
This commit is contained in:
commit
7c3f88606b
1 changed files with 30 additions and 12 deletions
|
@ -68,18 +68,8 @@ class MetadataFile < MetadataTemplate
|
|||
when ActionDispatch::Http::UploadedFile
|
||||
site.static_files.last if site.static_files.attach(value['path'])
|
||||
when String
|
||||
if (blob_id = ActiveStorage::Blob.where(key: key_from_path, service_name: site.name).pluck(:id).first)
|
||||
site.static_files.find_by(blob_id: blob_id)
|
||||
elsif path? && pathname.exist? && site.static_files.attach(io: pathname.open, filename: pathname.basename)
|
||||
site.static_files.last.tap do |s|
|
||||
s.blob.update(key: key_from_path)
|
||||
site.static_files.find_by(blob_id: blob_id) || migrate_static_file!
|
||||
end
|
||||
else
|
||||
raise ArgumentError, 'No se pudo subir el archivo'
|
||||
end
|
||||
end
|
||||
rescue ArgumentError => e
|
||||
ExceptionNotifier.notify_exception(e, data: { site: site.name, path: value['path'] })
|
||||
end
|
||||
|
||||
# Obtiene la ruta absoluta al archivo
|
||||
|
@ -95,7 +85,7 @@ class MetadataFile < MetadataTemplate
|
|||
#
|
||||
# @return [String]
|
||||
def key_from_path
|
||||
pathname.dirname.basename.to_s
|
||||
@key_from_path ||= pathname.dirname.basename.to_s
|
||||
end
|
||||
|
||||
def path?
|
||||
|
@ -148,4 +138,32 @@ class MetadataFile < MetadataTemplate
|
|||
def no_file_for_description?
|
||||
!path? && description?
|
||||
end
|
||||
|
||||
# Obtiene el id del blob asociado
|
||||
#
|
||||
# @return [Integer,nil]
|
||||
def blob_id
|
||||
@blob_id ||= ActiveStorage::Blob.where(key: key_from_path, service_name: site.name).pluck(:id).first
|
||||
end
|
||||
|
||||
# Genera el blob para un archivo que ya se encuentra en el
|
||||
# repositorio y lo agrega a la base de datos.
|
||||
#
|
||||
# @return [ActiveStorage::Attachment]
|
||||
def migrate_static_file!
|
||||
raise ArgumentError, 'El archivo no existe' unless path? && pathname.exist?
|
||||
|
||||
Site.transaction do
|
||||
blob =
|
||||
ActiveStorage::Blob.create_after_unfurling!(key: key_from_path,
|
||||
io: pathname.open,
|
||||
filename: pathname.basename,
|
||||
service_name: site.name)
|
||||
|
||||
ActiveStorage::Attachment.create!(name: 'static_files', record: site, blob: blob)
|
||||
end
|
||||
rescue ArgumentError => e
|
||||
ExceptionNotifier.notify_exception(e, data: { site: site.name, path: value['path'] })
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue