wechaty/puppet-gitter

Support image upload to gitter.

Closed this issue · 1 comments

huan commented

See:

  1. Odonno/modern-gitter-winjs#3 (comment)
  2. https://gitlab.com/gitlab-org/gitter/webapp/-/issues/2571#note_402273181

RESTFUL API Calls

Request URL: https://gitter.im/api_staging/private/generate-signature?room_id=5d007267d73408ce4fc3056f&type=image

{
   "sig":"f71ba84dd3a4b9e0b8c6654d58d80a927332ea12",
   "params":"{\"auth\":{\"max_size\":20971520,\"key\":\"7bd6c340a9d411e3853dfd1b6c578da0\",\"expires\":\"2020-08-27T10:12:49.540Z\"},\"template_id\":\"d98b7380f64811e387281f3cb8ebd11f\",\"fields\":{\"room_id\":\"5d007267d73408ce4fc3056f\",\"token\":\"UZYj\"},\"steps\":{\"export_originals\":{\"path\":\"${fields.room_id}/${fields.token}/${file.url_name}\"},\"export_thumbs\":{\"path\":\"${fields.room_id}/${fields.token}/thumb/${file.url_name}\"}},\"notify_url\":\"https://gitter.im/api_staging/private/transloadit/49b208e2-5390-429d-bd46-7a28d871788f\"}"
}

Request URL: https://api2.transloadit.com/instances/bored?callback=_jqjsp&_1598436769803=

_jqjsp({"ok":"BORED_INSTANCE_FOUND","host":"soro.transloadit.com","api2_host":"soro.transloadit.com"})

Request URL: https://soro.transloadit.com/assemblies/b300b9d0e78411eab53a419b5ade9f05?redirect=false

{
   "ok":"ASSEMBLY_EXECUTING",
   "message":"The Assembly is currently being executed.",
   "assembly_id":"b300b9d0e78411eab53a419b5ade9f05",
   "parent_id":null,
   "account_id":"7bd6c340a9d411e3853dfd1b6c578da0",
   "template_id":"d98b7380f64811e387281f3cb8ebd11f",
   "instance":"soro.transloadit.com",
   "assembly_url":"http://api2.soro.transloadit.com/assemblies/b300b9d0e78411eab53a419b5ade9f05",
   "assembly_ssl_url":"https://api2-soro.transloadit.com/assemblies/b300b9d0e78411eab53a419b5ade9f05",
   "uppyserver_url":"https://api2-soro.transloadit.com/companion/",
   "companion_url":"https://api2-soro.transloadit.com/companion/",
   "websocket_url":"https://api2-soro.transloadit.com/ws20097",
   "tus_url":"https://api2-soro.transloadit.com/resumable/files/",
   "bytes_received":1874,
   "bytes_expected":1874,
   "upload_duration":0.169,
   "client_agent":null,
   "client_ip":null,
   "client_referer":null,
   "transloadit_client":null,
   "start_date":"2020/08/26 10:12:52 GMT",
   "upload_meta_data_extracted":true,
   "warnings":[
      {
         "level":"notice",
         "msg":"Adding the bucket_region parameter to the /s3/store robot step \"export_originals\" can avoid problems and give you a nice performance boost. "
      },
      {
         "level":"notice",
         "msg":"Adding the bucket_region parameter to the /s3/store robot step \"export_thumbs\" can avoid problems and give you a nice performance boost. "
      }
   ],
   "is_infinite":false,
   "has_dupe_jobs":false,
   "execution_start":"2020/08/26 10:12:52 GMT",
   "execution_duration":0.172,
   "queue_duration":0.02,
   "jobs_queue_duration":0,
   "notify_start":null,
   "notify_url":"https://gitter.im/api_staging/private/transloadit/49b208e2-5390-429d-bd46-7a28d871788f",
   "notify_status":null,
   "notify_response_code":null,
   "notify_duration":null,
   "last_job_completed":null,
   "fields":{
      "numberOfFiles":1,
      "room_id":"5d007267d73408ce4fc3056f",
      "token":"UZYj"
   },
   "running_jobs":[
      
   ],
   "bytes_usage":0,
   "executing_jobs":[
      
   ],
   "started_jobs":[
      
   ],
   "parent_assembly_status":null,
   "params":"{\"auth\":{\"max_size\":20971520,\"key\":\"****\",\"expires\":\"2020-08-27T10:12:49.540Z\"},\"template_id\":\"d98b7380f64811e387281f3cb8ebd11f\",\"fields\":{\"room_id\":\"5d007267d73408ce4fc3056f\",\"token\":\"UZYj\"},\"steps\":{\"export_originals\":{\"path\":\"${fields.room_id}/${fields.token}/${file.url_name}\"},\"export_thumbs\":{\"path\":\"${fields.room_id}/${fields.token}/thumb/${file.url_name}\"}},\"notify_url\":\"https://gitter.im/api_staging/private/transloadit/49b208e2-5390-429d-bd46-7a28d871788f\"}",
   "template":"{\"steps\":{\"files\":{\"use\":\":original\",\"robot\":\"/file/filter\",\"accepts\":[[\"${file.mime}\",\"regex\",\"^image/\"]],\"error_on_decline\":true},\"img_thumbs\":{\"use\":\":original\",\"robot\":\"/image/resize\",\"imagemagick_stack\":\"v2.0.7\",\"width\":250,\"height\":250,\"zoom\":false,\"resize_strategy\":\"fit\"},\"export_originals\":{\"use\":[\":original\"],\"headers\":{\"Content-Type\":\"${file.mime}\"},\"robot\":\"/s3/store\",\"key\":\"****\",\"secret\":\"****\",\"bucket\":\"****\"},\"export_thumbs\":{\"use\":[\"img_thumbs\"],\"headers\":{\"Content-Type\":\"${file.mime}\"},\"robot\":\"/s3/store\",\"path\":\"${unique_prefix}/thumb/${file.url_name}\",\"key\":\"****\",\"secret\":\"****\",\"bucket\":\"****\"}}}",
   "merged_params":"{\"steps\":{\"files\":{\"use\":\":original\",\"robot\":\"/file/filter\",\"accepts\":[[\"${file.mime}\",\"regex\",\"^image/\"]],\"error_on_decline\":true},\"img_thumbs\":{\"use\":\":original\",\"robot\":\"/image/resize\",\"imagemagick_stack\":\"v2.0.7\",\"width\":250,\"height\":250,\"zoom\":false,\"resize_strategy\":\"fit\"},\"export_originals\":{\"use\":[\":original\"],\"headers\":{\"Content-Type\":\"${file.mime}\"},\"robot\":\"/s3/store\",\"key\":\"****\",\"secret\":\"****\",\"bucket\":\"****\",\"path\":\"${fields.room_id}/${fields.token}/${file.url_name}\"},\"export_thumbs\":{\"use\":[\"img_thumbs\"],\"headers\":{\"Content-Type\":\"${file.mime}\"},\"robot\":\"/s3/store\",\"path\":\"${fields.room_id}/${fields.token}/thumb/${file.url_name}\",\"key\":\"****\",\"secret\":\"****\",\"bucket\":\"****\"}},\"allow_steps_override\":true,\"auth\":{\"max_size\":20971520,\"key\":\"****\",\"expires\":\"2020-08-27T10:12:49.540Z\"},\"template_id\":\"d98b7380f64811e387281f3cb8ebd11f\",\"fields\":{\"room_id\":\"5d007267d73408ce4fc3056f\",\"token\":\"UZYj\"},\"notify_url\":\"https://gitter.im/api_staging/private/transloadit/49b208e2-5390-429d-bd46-7a28d871788f\"}",
   "uploads":[
      {
         "id":"4b2353b175ea4110998d0e38f75cfb30",
         "name":"image.png",
         "basename":"image",
         "ext":"png",
         "size":865,
         "mime":"image/png",
         "type":"image",
         "field":"file",
         "md5hash":"d3c0141d817a6c62517f97d19739ce7a",
         "original_id":"4b2353b175ea4110998d0e38f75cfb30",
         "original_basename":"image",
         "original_name":"image.png",
         "original_path":"/",
         "original_md5hash":"d3c0141d817a6c62517f97d19739ce7a",
         "from_batch_import":false,
         "is_tus_file":false,
         "tus_upload_url":null,
         "url":"http://tmp.transloadit.com.s3.amazonaws.com/4b2353b175ea4110998d0e38f75cfb30.png",
         "ssl_url":"https://s3.amazonaws.com/tmp.transloadit.com/4b2353b175ea4110998d0e38f75cfb30.png",
         "meta":{
            "width":64,
            "height":52,
            "date_recorded":null,
            "date_file_created":null,
            "date_file_modified":"2020/08/26 10:12:52 GMT",
            "title":null,
            "description":null,
            "duration":null,
            "location":null,
            "aspect_ratio":"1.231",
            "city":null,
            "state":null,
            "country":null,
            "country_code":null,
            "keywords":null,
            "aperture":null,
            "exposure_compensation":null,
            "exposure_mode":null,
            "exposure_time":null,
            "flash":null,
            "focal_length":null,
            "f_number":null,
            "iso":null,
            "light_value":null,
            "metering_mode":null,
            "shutter_speed":null,
            "white_balance":null,
            "device_name":null,
            "device_vendor":null,
            "device_software":null,
            "latitude":null,
            "longitude":null,
            "orientation":null,
            "has_clipping_path":false,
            "creator":null,
            "author":null,
            "copyright":null,
            "copyright_notice":null,
            "frame_count":1,
            "colorspace":"RGB",
            "has_transparency":null,
            "dominant_colors":null,
            "average_color":"#e8f0ee",
            "xp_title":null,
            "xp_comment":null,
            "xp_keywords":null,
            "xp_subject":null
         }
      }
   ],
   "results":{
      
   },
   "build_id":"854"
}

Message Payload

{
  operation: 'create',
  model: {
    id: '5f462cc338d0e2453d0a550c',
    text: '[![image.png](https://files.gitter.im/5d007267d73408ce4fc3056f/7rkf/thumb/image.png)](https://files.gitter.im/5d007267d73408ce4fc3056f/7rkf/image.png)',
    html: '<a href="https://files.gitter.im/5d007267d73408ce4fc3056f/7rkf/image.png" rel="nofollow noopener noreferrer" target="_blank" class="link "><img src="https://user-content.gitter-static.net/7d7f9a56db121130503d1b68cf11ad8a50710929/68747470733a2f2f66696c65732e6769747465722e696d2f3564303037323637643733343038636534666333303536662f37726b662f7468756d622f696d6167652e706e67" alt="image.png" rel="nofollow"></a>',
    sent: '2020-08-26T09:34:59.269Z',
    fromUser: {
      id: '5527c40c15522ed4b3dece74',
      username: 'huan',
      displayName: 'Huan (李卓桓)',
      url: '/huan',
      avatarUrl: 'https://avatars-staging-05.gitter.im/gh/uv/4/huan',
      avatarUrlSmall: 'https://avatars1.githubusercontent.com/u/1361891?v=4&s=60',
      avatarUrlMedium: 'https://avatars1.githubusercontent.com/u/1361891?v=4&s=128',
      v: 79,
      gv: '4'
    },
    readBy: 0,
    urls: [ [Object], [Object] ],
    mentions: [],
    issues: [],
    meta: [],
    v: 1
  }
}
huan commented

It has been implemented beautifully today!