2020-05-26 18:08:20 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Types
|
2020-06-18 15:08:45 +00:00
|
|
|
class ReleaseAssetLinkType < BaseObject
|
|
|
|
graphql_name 'ReleaseAssetLink'
|
2020-06-18 06:08:33 +00:00
|
|
|
description 'Represents an asset link associated with a release'
|
2020-05-26 18:08:20 +00:00
|
|
|
|
|
|
|
authorize :read_release
|
|
|
|
|
2021-07-23 12:09:05 +00:00
|
|
|
field :id, GraphQL::Types::ID, null: false,
|
2021-02-05 15:09:28 +00:00
|
|
|
description: 'ID of the link.'
|
2021-07-23 12:09:05 +00:00
|
|
|
field :name, GraphQL::Types::String, null: true,
|
2021-02-05 15:09:28 +00:00
|
|
|
description: 'Name of the link.'
|
2021-07-23 12:09:05 +00:00
|
|
|
field :url, GraphQL::Types::String, null: true,
|
2021-02-05 15:09:28 +00:00
|
|
|
description: 'URL of the link.'
|
2020-06-18 15:08:45 +00:00
|
|
|
field :link_type, Types::ReleaseAssetLinkTypeEnum, null: true,
|
2021-02-05 15:09:28 +00:00
|
|
|
description: 'Type of the link: `other`, `runbook`, `image`, `package`; defaults to `other`.'
|
2021-07-23 12:09:05 +00:00
|
|
|
field :external, GraphQL::Types::Boolean, null: true, method: :external?,
|
2021-02-05 15:09:28 +00:00
|
|
|
description: 'Indicates the link points to an external resource.'
|
2020-09-11 00:08:51 +00:00
|
|
|
|
2021-07-23 12:09:05 +00:00
|
|
|
field :direct_asset_url, GraphQL::Types::String, null: true,
|
2021-02-05 15:09:28 +00:00
|
|
|
description: 'Direct asset URL of the link.'
|
2021-07-23 12:09:05 +00:00
|
|
|
field :direct_asset_path, GraphQL::Types::String, null: true, method: :filepath,
|
2021-06-28 21:10:13 +00:00
|
|
|
description: 'Relative path for the direct asset link.'
|
2020-09-11 00:08:51 +00:00
|
|
|
|
|
|
|
def direct_asset_url
|
|
|
|
return object.url unless object.filepath
|
|
|
|
|
2020-11-12 15:09:09 +00:00
|
|
|
release = object.release.present
|
|
|
|
release.download_url(object.filepath)
|
2020-09-11 00:08:51 +00:00
|
|
|
end
|
2020-05-26 18:08:20 +00:00
|
|
|
end
|
|
|
|
end
|