3

Scratch3技术分析之Studio API(第8篇)

 3 years ago
source link: http://wwj718.github.io/post/%E5%B0%91%E5%84%BF%E7%BC%96%E7%A8%8B/scratch3-studio/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

本文是Scratch3.0技术分析之后端API系列的第8篇。

Studio

Studio是Scratch社区的重要构成部分。

Studio在概念上颇似项目收纳盒,用户可以将感兴趣的项目添加到收纳盒中。

Scratch团队还未完成Studio API的重构。目前要创建Studio,须从旧网页进入,url为:https://scratch.mit.edu/mystuff/#galleries, 从url可以看出Studiogalleries被scratch视为同义词。

如果你用过知乎或者掘金。会发现Studio收藏夹颇为相似。

之前在做paperweekly时,收藏夹部分参考了知乎掘金producthunt。各家大同小异,核心概念都是收纳盒/collections

产品视角: 不同之处

接下来说说Studio和知乎收藏夹的不同之处。

Scratch推崇4P(Projects, Passion, Peers, Play)原则, 它们将理念贯彻到产品中。

StudioProjects的收纳盒,用户兴趣各异,Passion各有不同。用户创建Studio一般从某种兴趣点出发。

至此,studios知乎收藏夹并没有什么差异。

我们可以看看Scratch社区里受欢迎的studios

由于社区里有兴趣相似的人,人们会对其他用户创建的收纳盒感兴趣,于是收纳盒应该支持关注/follow功能,在这点上,各家依旧没什么差别。

Peers的重视,是引起差异的原因。Scratch把社区用户视为潜在的协作者/Peers, 而知乎/掘金的收藏夹背后的逻辑则是把关注者视为围观群众

于是在产品定位和功能上就出现了根本差异。

在Scratch中,用户可以为Studio添加curators:

curators与Studio的创建者一样,可以一起维护这个Studio(本质上是个权限系统),curators拥有往Studio里增删项目的权利。

Studio甚至有个可选项Allow anyone to add projects: 将整个社区视为协作者。

Studio和Porject一样,都是Scratch的一等公民,我们可以看到Studio和Porject类似,有自己的title、缩略图(标注1)、简介(标注2)和评论(标注3),此外还有活动日志(标注4)。

API分析

至此,我们基本上做完了产品层面的分析。

接下来我们开始API层面的分析。

创建Studio

让我们在https://scratch.mit.edu/mystuff/New Studio

细节如下:

创建完成后,重定向到 https://scratch.mit.edu/studios/8259659/, 该页面目前并未API化,应该是Django模版渲染的。

更新Studio信息

让我们将title更新为test2:

采用的是PUT方法,以表单方式提交数据

更新描述信息也相似。对应字段名为description

更新封面图片, 是用POST方式往https://scratch.mit.edu/site-api/galleries/all/8259659/提交图片,细节为:

提交之后,图片地址为://cdn2.scratch.mit.edu/get_image/gallery/8259659_200x118.png#1556595638951

可以看出带了时间戳,应该是出于缓存更新目的。

图片限制为: Maximum file size is 512 KB and less than 500x500 pixels.

往Studio里增删项目

这部分的功能已经迁移到Scratch新版网站中。

将项目添加到Studio中时,发生的细节为:

POST https://api.scratch.mit.edu/studios/8259659/project/302042626

response为{"actorId":18286387,"projectId":"302042626","datetimeCreated":"2019-04-30 03:45:31","studioId":"8259659"}

删除操作对应:DELETE https://api.scratch.mit.edu/studios/8259659/project/302042626, response为[]

关注(Follow) Studio

PUT https://scratch.mit.edu/site-api/users/bookmarkers/8259659/add/?usernames=wwj718

response:[{"featured_project_label_name": "Featured Project", "featured_project_data": null, "featured_project": null, "thumbnail_url": "//uploads.scratch.mit.edu/users/avatars/18286387.png", "user": {"username": "wwj718", "pk": 18286387}, "featured_project_label_id": null, "id": 17449452}]

邀请用户成为Studio的curators

PUT https://scratch.mit.edu/site-api/users/curators-in/8259659/invite_curator/?usernames=tonynsc

response为: {"status": "success", "data": {"user": "tonynsc"}}

Studio的评论

POST https://scratch.mit.edu/site-api/comments/gallery/8259659/add/

以表单形式提交:{"content":"test","parent_id":"","commentee_id":""}

POST https://scratch.mit.edu/site-api/comments/gallery/8259659/add/

以表单形式提交:{"content":"test","parent_id":56665892,"commentee_id":18286387}

目前Studio的API官方还在重构中,完成之后,我会同步更新这篇文章。


Recommend

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK