七牛云图床存储+Alfread工做流+使用QSHELL


layout: post
title: 七牛云图床存储+Alfread工做流+使用QSHELLjavascript

来源:http://www.cnblogs.com/cmi-sh-love/p/8901620.html

七牛云图床存储+Alfread工做流+使用QSHELL

使用markdown最头疼的问题就是贴图问题。有多种方式来上传图片到图床,并得到外链的方面。而咱们所但愿最便捷以及最天然的方式就是,截取图片,而后粘贴进MarkDown编辑器的时候就自动上传到图床而且完成Markdown图片格式的编写。简单来讲就是但愿粘贴的时候就像粘贴图片到word同样,而后这些图片又是基于外链的,能够在任何有互联网的地方显示出来。html

准备工做

大致能够分为三个部分:
1.七牛云的配置
2.qshell的配置
3.Alfread的配置java

1.七牛云的配置

1.1 注册

若是尚未七牛云存储的帐号,能够自行前往官网申请帐号。提供10G的免费存储空间,每月10G的下载流量、10万次PUT/DELETE请求、100万次GET请求。注册你们都会就不说了。shell

1.2 新建空间与设置样式




在样式里面能够新建多种样式,来控制图片大小,毕竟markdown语法不能控制图片大小
json

1.3新建一个密匙用于qshell访问

在我的面板点击密钥管理

新建一个密钥,包含AccessKey/SecretKey,后面配置qshell须要用到
七牛云存储

2.qshell的配置

到https://developer.qiniu.com/kodo/tools/1302/qshell下载QSHELL,下载mac版本后重命名为qshell

新建目录用于放置配置文件以及数据文件以下:

修改qshell文件的权限,使他成为可执行文件
chmod 755 /User/apple/Download/qshell
并将qshell文件放置在CLI目录下,并在CLI目录建立conf.json配置文件,内容以下:markdown

{
  "src_dir":"/Users/think/QiNiu/Data/",##本地图片数据目录
  "bucket":"markdownImage",##七牛云空间名称
  "rescan_local":true,
  "check_exists":true,
  "check_hash":true,
  "check_size":true
}

配置qshell密钥,在CLI目录下打开终端,使用命令设置密钥app

qshell account [AccessKey] [SecretKey]
例如:qshell account kdajfiaifsanmflkwajfoiwr _fdaskrlakkkdasfanjjjj编辑器

  • 其中[AccessKey]和[SecretKey]为上面咱们生成的密钥.
  • 配置 qshell 完毕后会生成 ~/.qshell 文件夹,其中 account.json 文件保存了 AccessKey 和 SecretKey 信息。

3.Alfread的配置

下载Alfred安装包并安装, 须要购买 Powerpack 才能解锁 workflows 功能,或者自行收索和谐版。
下载工做流:百度云盘 密码:q18a
导入以后修改脚本。
post

脚本内容以下。

property fileTypes : {¬
    {«class PNGf», ".png"}, ¬
    {JPEG picture, ".jpg"}}
on getType()
    repeat with aType in fileTypes
        repeat with theInfo in (clipboard info)
            if (first item of theInfo) is equal to (first item of aType) then return aType
        end repeat
    end repeat
    return missing value
end getType
set theType to getType()
if theType is not missing value then
    set filePath to "/Users/think/QiNiu/Data/" --这里换成你本身放置图片的路径
    set fileName to do shell script "date \"+%Y%m%d%H%M%S\" | md5" --用当前时间的md5值作文件名
    if fileName does not end with (second item of theType) then set fileName to (fileName & second item of theType as text)
    set markdownUrl to "![](http://p7iq38s6i.bkt.clouddn.com/" & fileName & "-480p)" --这里是你的七牛域名和设置的图片样式
    set filePath to filePath & fileName
    try
        set imageFile to (open for access filePath with write permission)
        set eof imageFile to 0
        write (the clipboard as (first item of theType)) to imageFile
        close access imageFile
        set the clipboard to markdownUrl
        try
            tell application "System Events"
                keystroke "v" using command down
            end tell
        end try
        do shell script "/Users/think/QiNiu/CLI/qshell qupload /Users/think/QiNiu/CLI/conf.json" 
    on error
        try
            close access imageFile
        end try
        return ""
    end try
else
    return ""
end if

须要修改以下地方
set filePath to "/Users/think/QiNiu/Data/" --这里换成你本身放置图片的路径
set markdownUrl to "![](http://p7iq38s6i.bkt.clouddn.com/" & fileName & "-480p)"--这里是你的七牛域名和设置的图片样式,若没有样式使用set markdownUrl to "![](http://p7iq38s6i.bkt.clouddn.com/" & fileName & ")"
do shell script "/Users/think/QiNiu/CLI/qshell qupload /Users/think/QiNiu/CLI/conf.json" 修改以后保持,并为工做流添加快捷键。粘贴的时候使用快捷键粘贴便可

相关文章
相关标签/搜索