Skip to content

Commit

Permalink
bump version 1.13
Browse files Browse the repository at this point in the history
  • Loading branch information
staugur committed May 15, 2021
1 parent da15416 commit 87a2ab2
Show file tree
Hide file tree
Showing 11 changed files with 104 additions and 34 deletions.
24 changes: 19 additions & 5 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -378,15 +378,29 @@ RESTful API

增加title和expire字段,前者设置图片描述,后者添加为临时图片

获取上传数据的字段默认是picbed,管理员可以在控制台修改,但是不建议改,
如果要改,首页上传会自动更新,但引用uploader.js在外部上传的话,那就需要
设置 **name** 值,具体参考 :ref:`LinkToken-upload-plugin` ,有一个name选项
可以设置其他值。
.. versionchanged:: 1.13.0

真正实现上传限制!

之前的版本在后台设置的上传限制仅仅在首页上传时由前端限制,后端接口并无限制,
现在『弯道超车』目前三种上传方式都有size接口读取上传大小进而限制。

增加了 `_upload_field` 指定上传字段。

允许上传视频(beta)!

.. note::

获取上传数据的字段默认是picbed,管理员可以在控制台修改,但是不建议改,
如果要改,首页上传会自动更新,但引用uploader.js在外部上传的话,那就需要
设置 **name** 值,具体参考 :ref:`LinkToken-upload-plugin` ,有一个name选项
可以设置其他值。

:query string format: 指定图片地址的显示字段
:form format: 等于query查询参数的format
:form album: 图片所属相册(匿名时总是直接设置为anonymous)
:form picbed: 上传字段名
:form _upload_field: 指定上传字段,否则依次读取后台设置、默认值(picbed)
:form picbed: 上传字段名(可由后台设置)
:form title: 图片简单描述,页面显示时作为title
:form expire: 表明上传临时图片,int类型,单位秒,过期删除数据(不会物理删除图片)
:form filename: 使用 **base64/url** 方式上传时此值有效,设定文件名
Expand Down
25 changes: 25 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,31 @@
更新日志
=========

v1.13.0
--------

Released in 2021-05-15

功能:
- 管理员控制台 `Ctrl/Command + S` 快捷键保存配置
- 关于本站:公开了部分公共信息
- 上传字段用户可由 `_upload_field` 自行指定。
- 上传视频功能(及周边兼容),api、cli、homepage均支持

优化:
- 上传大小限制,后端接口实现

更改:
- 部分picbed字样更改为sapic
- 更新文档
- 更新hook
- 配置读取环境变量时兼容sapic前缀
- docker镜像同时上传 staugur/picbed 和 staugur/sapic
- cli客户端命令行工具兼容

修复:
- 尝试性修复 nginx with docker 模式下 local 生成 https url 问题(感谢@Nestle)

v1.12.0
--------

Expand Down
48 changes: 26 additions & 22 deletions docs/cli.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ cli.py的使用说明仍然可以 :doc:`在这里 <cli-py>` 找到。
为适应 v1.12.0 正式名称 sapic ,此 picbed-cli 命令行客户端程序自 v0.5 同步改名
为 sapicli ,源码仓库是: https://github.com/sapicd/cli

.. versionchanged:: 0.5.2

发版时tag增加 `v` 前缀,以便 go module 使用。

不同点
-------

Expand Down Expand Up @@ -89,26 +93,26 @@ ps: 上述github页面如果访问速度不佳,可以点击下列文件名下
======================================= ================================
文件名 MD5
======================================= ================================
picbed-cli.0.4.0-linux-amd64.tar.gz_ 82bf4fb8bd683336af782e85fef1dbf0
picbed-cli.0.4.0-darwin-amd64.tar.gz_ 128f9b94306764cdb902b153da9cdfdb
picbed-cli.0.4.0-windows-amd64.zip_ d46702262048143b211839ed3d53a8a2
sapicli.0.5.2-linux-amd64.tar.gz_ 9f0d49c7bee77ac2b631f8aba006a3a5
sapicli.0.5.2-darwin-amd64.tar.gz_ ea51cfe839d64b9189ce1e2ddf42dde6
sapicli.0.5.2-windows-amd64.zip_ 88bb1637c10afed5d974e73bc0e36b13

picbed-cli.0.4.2-linux-amd64.tar.gz_ 2d95386da32ac1a7e81247f325468847
picbed-cli.0.4.2-darwin-amd64.tar.gz_ f59a03443e70341fb925b63d3dcaf482
picbed-cli.0.4.2-windows-amd64.zip_ d70185370d6658e9a8b37fcd9323ef74
sapicli.0.5.1-linux-amd64.tar.gz_ f105234f5b229cbde29401a63a992d4f
sapicli.0.5.1-darwin-amd64.tar.gz_ 41712bcf7b0f31c4bdb3446d7643a850
sapicli.0.5.1-windows-amd64.zip_ a7185dc5a514d0a436fe7dc7db499230

sapicli.0.5.0-linux-amd64.tar.gz_ fc02ddd2276f0d099c9b8419f6ff1ceb
sapicli.0.5.0-darwin-amd64.tar.gz_ e92461ae95c8bd8050b06bb94e14d44f
sapicli.0.5.0-windows-amd64.zip_ 5058890071c24e121f6109d3087eccaf
======================================= ================================

.. _picbed-cli.0.4.0-linux-amd64.tar.gz: https://static.saintic.com/download/picbed-cli/picbed-cli.0.4.0-linux-amd64.tar.gz
.. _picbed-cli.0.4.0-darwin-amd64.tar.gz: https://static.saintic.com/download/picbed-cli/picbed-cli.0.4.0-darwin-amd64.tar.gz
.. _picbed-cli.0.4.0-windows-amd64.zip: https://static.saintic.com/download/picbed-cli/picbed-cli.0.4.0-windows-amd64.zip
.. _sapicli.0.5.2-linux-amd64.tar.gz: https://static.saintic.com/download/sapicli/sapicli.0.5.2-linux-amd64.tar.gz
.. _sapicli.0.5.2-darwin-amd64.tar.gz: https://static.saintic.com/download/sapicli/sapicli.0.5.2-darwin-amd64.tar.gz
.. _sapicli.0.5.2-windows-amd64.zip: https://static.saintic.com/download/sapicli/sapicli.0.5.2-windows-amd64.zip

.. _picbed-cli.0.4.2-linux-amd64.tar.gz: https://static.saintic.com/download/picbed-cli/picbed-cli.0.4.2-linux-amd64.tar.gz
.. _picbed-cli.0.4.2-darwin-amd64.tar.gz: https://static.saintic.com/download/picbed-cli/picbed-cli.0.4.2-darwin-amd64.tar.gz
.. _picbed-cli.0.4.2-windows-amd64.zip: https://static.saintic.com/download/picbed-cli/picbed-cli.0.4.2-windows-amd64.zip
.. _sapicli.0.5.1-linux-amd64.tar.gz: https://static.saintic.com/download/sapicli/sapicli.0.5.1-linux-amd64.tar.gz
.. _sapicli.0.5.1-darwin-amd64.tar.gz: https://static.saintic.com/download/sapicli/sapicli.0.5.1-darwin-amd64.tar.gz
.. _sapicli.0.5.1-windows-amd64.zip: https://static.saintic.com/download/sapicli/sapicli.0.5.1-windows-amd64.zip

.. _sapicli.0.5.0-linux-amd64.tar.gz: https://static.saintic.com/download/picbed-cli/sapicli.0.5.0-linux-amd64.tar.gz
.. _sapicli.0.5.0-darwin-amd64.tar.gz: https://static.saintic.com/download/picbed-cli/sapicli.0.5.0-darwin-amd64.tar.gz
Expand All @@ -133,7 +137,7 @@ sapicli.0.5.0-windows-amd64.zip_ 5058890071c24e121f6109d3087eccaf
[-d DESC] [-e EXPIRE] [-s STYLE] [-c {url,md,rst}]
file [file ...]
Doc to https://picbed.rtfd.vip/cli.html
Doc to https://sapic.rtfd.vip/cli.html
Git to https://github.com/sapicd/cli
positional arguments:
Expand All @@ -143,12 +147,12 @@ sapicli.0.5.0-windows-amd64.zip_ 5058890071c24e121f6109d3087eccaf
-h, --help show this help message and exit
-v, --version show cli version and exit
-i, --info show full info and exit
-u, --picbed-url PICBED_URL
The picbed upload api url.
Or use environment variable: picbed_cli_apiurl
-t, --picbed-token PICBED_TOKEN
The picbed LinkToken.
Or use environment variable: picbed_cli_apitoken
-u, --sapic-url SAPIC_URL
The sapic upload api url.
Or use environment variable: sapicli_apiurl
-t, --sapic-token SAPIC_TOKEN
The sapic LinkToken.
Or use environment variable: sapicli_apitoken
-a, --album ALBUM Set image album
-d, --desc DESC Set image title(description)
-e, --expire EXPIRE Set image expire(seconds)
Expand All @@ -160,12 +164,12 @@ sapicli.0.5.0-windows-amd64.zip_ 5058890071c24e121f6109d3087eccaf
for win/mac/linux.
By the way, md=markdown, rst=reStructuredText
-u: 指定图床的服务地址,http[s]://你的picbed域名[/api/upload]
- 可以通过环境变量 **picbed_cli_apiurl** 设定
-u: 指定图床的服务地址,http[s]://你的picbed(sapic)域名[/api/upload]
- 可以通过环境变量 **picbed_cli_apiurl** **sapicli_apiurl** 设定
- 可以省略http,可以省略末尾/api/upload
-t: 设置LinkToken用以认证、授权,要求拥有 ``api.upload````post`` 权限
可以通过环境变量 **picbed_cli_apitoken** 设定
可以通过环境变量 **picbed_cli_apitoken** **sapicli_apitoken** 设定
-a: 设置相册名(可以覆盖LinkToken设置的默认相册)
Expand Down
5 changes: 5 additions & 0 deletions docs/faq.rst
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,8 @@ ps:docker-compose用户可以在docker-compose.yml中添加以下变量再构
.. code-block::
- picbed_secretkey = abcdefg
6. 能上传视频吗
-----------------

v1.13.0支持,进入beta,可由后台开启。
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Gitee:https://gitee.com/staugur/picbed

3. API

- 基于api的上传接口,支持通过文件域、base64(允许Data URI形式)、Image URL上传
- 基于api的上传接口,支持通过文件域、base64(允许Data URI形式)、URL上传
- 可定制的api响应数据[及字段]及中英错误消息提示
- 支持Token以及更安全的基于Token的LinkToken调用api
- 外部网站通过按钮一键上传的插件
Expand Down
12 changes: 12 additions & 0 deletions docs/module.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ Modules API

默认允许上传的图片后缀

.. data:: ALLOWED_VIDEO

允许上传的视频后缀

.. autofunction:: rsp

.. autofunction:: md5
Expand Down Expand Up @@ -66,6 +70,8 @@ Modules API

.. autofunction:: is_valid_verion

.. autofunction:: b64size

.. autoclass:: Mailbox
:members:

Expand Down Expand Up @@ -114,6 +120,8 @@ Modules API

.. autofunction:: guess_filename_from_url

.. autofunction:: get_allowed_suffix

.. autofunction:: allowed_suffix

.. autoclass:: Base64FileStorage
Expand All @@ -124,6 +132,10 @@ Modules API
:members:
:undoc-members:

.. autoclass:: FormFileStorage
:members:
:undoc-members:

异常类
--------

Expand Down
6 changes: 5 additions & 1 deletion docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ Chrome, Microsoft Edge, Safari, Opera Next, 和 Firefox。

|picbed_userscript|

脚本地址: `Your Picbed URL/picbed.user.js`
脚本地址: `Your Picbed URL/picbed.user.js` 或 `Your Sapic URL/sapic.user.js`

只有开启用户脚本后才能产生脚本链接,不严格要求填写LinkToken,但是没有的话将
会是匿名上传且不支持脚本更新。
Expand Down Expand Up @@ -323,6 +323,10 @@ Web中只有首页可以上传,同时最多选择10张,默认支持jpg、jpe
符合 `http://` 或 `https://` 的合法URL会进入图片链接上传模式,
:ref:`参考Upload Api <picbed-api-upload>`

.. versionchanged:: 1.13.0

支持视频上传(beta),默认未开启,需要管理员开启。

.. _picbed-upload-example:

3.1 以下是几个客户端(通过API)上传的示例:
Expand Down
2 changes: 1 addition & 1 deletion src/templates/public/feed.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<link>{{ i.src }}</link>
<description>
{% if is_true(i.is_video) -%}
<![CDATA[<video src="{{ i.src }}" controls style="top:0; left:0; max-width:80px;padding-top:61px;"></video>]]>
<![CDATA[<video src="{{ i.src }}" controls></video>]]>
{% else %}
<![CDATA[<img src="{{ i.src }}">]]>
{% endif %}
Expand Down
2 changes: 2 additions & 0 deletions src/utils/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ def get_today(fmt="%Y/%m/%d"):


def allowed_file(filename, suffix=None):
if not filename:
return False
suffix = set(suffix or ALLOWED_EXTS)
return '.' in filename and \
filename.rsplit('.', 1)[1].lower() in suffix
Expand Down
6 changes: 4 additions & 2 deletions src/utils/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,7 @@ def force_type(cls, rv, environ=None):


class FormFileStorage(object):
"""通过表单上传文件"""

def __init__(self, fp):
self._fp = fp
Expand Down Expand Up @@ -475,6 +476,7 @@ def __init__(self, b64str, filename=None):
self._parse = parse_data_uri(self._b64str)
if self.is_base64:
try:
#: now data change to binary
self._parse["data"] = pic64decode(self._parse.data)
except (BaseDecodeError, TypeError, ValueError):
raise ValueError("The attempt to decode the image failed")
Expand All @@ -498,7 +500,7 @@ def filename(self):
ext = imghdr.what(None, self._parse.data)
if not ext and self.mimetype:
mType, sType = self.mimetype.split("/")
if mType == "image":
if mType == "image": # without parse video
ext = sType
self._filename = "{}.{}".format(get_current_timestamp(), ext)
return self._filename
Expand All @@ -516,7 +518,7 @@ def stream(self):
def size(self):
"""return bytes"""
if self.is_base64:
return b64size(self._parse.data)
return b64size(self._b64str)

def __bool__(self):
return self.is_base64
Expand Down
6 changes: 4 additions & 2 deletions src/views/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1223,9 +1223,11 @@ def upload():
except (ValueError, TypeError):
raise ApiError("Invalid expire param")
#: 尝试读取上传数据
fp = FormFileStorage(request.files.get(FIELD_NAME))
fp = request.files.get(FIELD_NAME)
#: 当fp无效时尝试读取base64或url
if not fp:
if fp:
fp = FormFileStorage(fp)
else:
picstrurl = request.form.get(FIELD_NAME)
filename = secure_filename(request.form.get("filename") or "")
if picstrurl:
Expand Down

0 comments on commit 87a2ab2

Please sign in to comment.