第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定

Atom插件開發(fā)-使用自己的Chevereto圖床API

Atom插件开发-使用自己的Chevereto图床API

最近一直在用 Atom 写写markdown,但无奈上传图片真实太麻烦了。找了好几个插件都是要用到 七牛 的账号,由于之前被七牛坑过一次,就没再想用他的打算了。一度放弃后使用在线的markdown,例如简书 掘金 这些,可感觉用起来还是不太舒服,最终还是折腾起atom插件了。

正好之前有建了个图床站还顺带出了个iOS的App 米米图床 (我是奸商我收费)

也写过一篇相关的文章 iOS开发-RAC+MVVM练手项目 图床App

项目简介

由于自己有图床 目前使用的是 Chevereto
本文所涉及到内容都是根据 此API文档

所以这款插件只为解决几个问题

  • 使用自己图床的API
  • 上传图片获得URL
功能分析

功能灰常简单

  • 获取剪切板图片数据
  • 通过post上传至图床API获得回调数据
  • 生成markdown图片内容

根据API文档 我们用 Postman 测一下API 看看回调

嗯 回调的内容很多,我们就挑一个display_url这个字段吧,够用就行。

代码实现

用的是coffeescript代码

第三方依赖 request


module.exports =
  # setting 中的全局变量
  config:
    Api:
      title: "Your api url"
      description: "Input your api url like `https://xxx.com/api/1/upload`"
      type: 'string'
      default: "https://imgurl.xyz/api/1/upload"
    ApiKey:
      title: "ApiKey"
      description: "Input your api key, you can find it in your dashboard, default is my key ,Do not mark sure always available"
      type: 'string'
      default: "a7bb2b091e3f2961e59551a8cf6e05b2"

  activate: (state) ->
    @attachEvent()

  attachEvent: ->
    workspaceElement = atom.views.getView(atom.workspace)
    workspaceElement.addEventListener 'keydown', (e) =>
      # cmd + paste
      if (e.metaKey && e.keyCode == 86)
        # clipboard readImage
        clipboard = require('clipboard')
        img = clipboard.readImage()
        return if img.isEmpty()

        clipboard.writeText('')

        # insert loading text
        editor = atom.workspace.getActiveTextEditor()
        range = editor.insertText('uploading...');

        @postToImgur img, (imgUrl) ->
          # replace loading text to markdown img format
          markdown = "![](#{imgUrl})"
          editor.setTextInBufferRange(range[0], markdown)

  postToImgur: (img, callback) ->

    req = require('request')
    options = {
      uri: atom.config.get('image-copy-chevereto.Api')
      formData: {
        action : 'upload'
        key : atom.config.get('image-copy-chevereto.ApiKey')
        source : img.toPNG().toString('base64')
      }
      json: true
    }
    req.post options, (error, response, body) ->
      if (!error && response.statusCode == 200)
        callback(body.image.display_url) if callback && body.image.display_url
      else
        callback('error ')
项目地址

插件中默认使用的apiurl和key都是自己的 不保证会完全变,有条件的建议还是使用自己的apiurl和key) 还有。。。暂不支持gif

插件安装:直接Atom perference->install 中搜索 image-copy-chevereto即可 (

插件地址:https://atom.io/packages/image-copy-chevereto

gayhub地址: https://github.com/gongxiaokai/image-copy-chevereto

欢迎点赞~

點擊查看更多內(nèi)容
5人點贊

若覺得本文不錯,就分享一下吧!

評論

作者其他優(yōu)質(zhì)文章

正在加載中
移動開發(fā)工程師
手記
粉絲
14
獲贊與收藏
82

關(guān)注作者,訂閱最新文章

閱讀免費教程

感謝您的支持,我會繼續(xù)努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦
今天注冊有機會得

100積分直接送

付費專欄免費學

大額優(yōu)惠券免費領(lǐng)

立即參與 放棄機會
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號

舉報

0/150
提交
取消