2022-08-12 05:05:57 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class LabelTemplatesPreviewService
|
|
|
|
extend Service
|
|
|
|
|
|
|
|
attr_reader :error, :preview
|
|
|
|
|
2022-08-24 19:55:54 +08:00
|
|
|
def initialize(params, user)
|
2022-08-12 05:05:57 +08:00
|
|
|
@user = user
|
|
|
|
@params = params
|
|
|
|
end
|
|
|
|
|
|
|
|
def generate_zpl_preview!
|
|
|
|
client = Aws::Lambda::Client.new(region: ENV['AWS_REGION'])
|
|
|
|
resp = client.invoke(
|
|
|
|
function_name: 'BinaryKitsZplViewer',
|
|
|
|
invocation_type: 'RequestResponse',
|
|
|
|
log_type: 'Tail',
|
2022-08-24 19:55:54 +08:00
|
|
|
payload:
|
|
|
|
"{ \"content\": #{@params[:zpl].to_json},"\
|
|
|
|
"\"width\": #{@params[:width]},"\
|
|
|
|
"\"height\": #{@params[:height]},"\
|
|
|
|
"\"density\": #{@params[:density]} "\
|
|
|
|
"}"
|
2022-08-12 05:05:57 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
if resp.function_error.nil?
|
2022-08-24 19:55:54 +08:00
|
|
|
@preview = resp.payload.string.delete('"')
|
2022-08-12 05:05:57 +08:00
|
|
|
else
|
2022-08-24 19:55:54 +08:00
|
|
|
@error = resp.function_error.string
|
2022-08-12 05:05:57 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|