2020-06-23 00:09:42 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Types
|
2020-07-28 23:09:34 +05:30
|
|
|
class ReleaseAssetLinkType < BaseObject
|
|
|
|
graphql_name 'ReleaseAssetLink'
|
|
|
|
description 'Represents an asset link associated with a release'
|
2020-06-23 00:09:42 +05:30
|
|
|
|
|
|
|
authorize :read_release
|
|
|
|
|
|
|
|
field :id, GraphQL::ID_TYPE, null: false,
|
2021-03-11 19:13:27 +05:30
|
|
|
description: 'ID of the link.'
|
2020-06-23 00:09:42 +05:30
|
|
|
field :name, GraphQL::STRING_TYPE, null: true,
|
2021-03-11 19:13:27 +05:30
|
|
|
description: 'Name of the link.'
|
2020-06-23 00:09:42 +05:30
|
|
|
field :url, GraphQL::STRING_TYPE, null: true,
|
2021-03-11 19:13:27 +05:30
|
|
|
description: 'URL of the link.'
|
2020-07-28 23:09:34 +05:30
|
|
|
field :link_type, Types::ReleaseAssetLinkTypeEnum, null: true,
|
2021-03-11 19:13:27 +05:30
|
|
|
description: 'Type of the link: `other`, `runbook`, `image`, `package`; defaults to `other`.'
|
2020-06-23 00:09:42 +05:30
|
|
|
field :external, GraphQL::BOOLEAN_TYPE, null: true, method: :external?,
|
2021-03-11 19:13:27 +05:30
|
|
|
description: 'Indicates the link points to an external resource.'
|
2020-11-24 15:15:51 +05:30
|
|
|
|
|
|
|
field :direct_asset_url, GraphQL::STRING_TYPE, null: true,
|
2021-03-11 19:13:27 +05:30
|
|
|
description: 'Direct asset URL of the link.'
|
2020-11-24 15:15:51 +05:30
|
|
|
|
|
|
|
def direct_asset_url
|
|
|
|
return object.url unless object.filepath
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
release = object.release.present
|
|
|
|
release.download_url(object.filepath)
|
2020-11-24 15:15:51 +05:30
|
|
|
end
|
2020-06-23 00:09:42 +05:30
|
|
|
end
|
|
|
|
end
|