actooors / shumessage_service Goto Github PK
View Code? Open in Web Editor NEWshumessage的项目后端
shumessage的项目后端
逻辑:
注意:
{
type:0,
id:101
}
{
code:"SUCCESS",
message:null,
data:null
}
deleteInfo:{
executor:{
id:16121888,
name:"诸葛亮"
},
deleteTime:"2018-08-26T15:15:04Z"
}
若消息未被删除,请不要在消息中携带deleteInfo(建议),或统一赋值null(alternate)
该api用于获取某个消息(如新闻消息)的评论列表。注意,评论这一层下面又有一层回复,也就是说回复是对评论的评论,回复是最底层,叶子结点,没有回复的回复。
获取热门评论和最新评论:
{
type:0,//假设0对应新闻
id:10001,//我要获取id为10001这条新闻的评论列表
page:1,
limit:[5,20]//第一个block限制5条,第二个block限制20条。block的定义请看response部分
}
更新列表(获取更多最新评论):
{
type:0,//假设0对应新闻
id:10001,//我要获取id为10001这条新闻的评论列表
page:2,
limit:[0,20]//不获取热门评论,第二个block限制20条。block的定义请看response部分
}
注意,response有个特点,它的格式是通用的,raw是一个数组,我们可以看到app里面点开详情查看评论的时候分为两个block,一个是热门评论(按特定算法从所有评论中取得),一个是最新评论,那么对应的raw就是一个两个元素的数组。demo如下列code。
而点进一条评论的详情,我们可以看到只有一个block,那么这时候response返回的raw就是一个包含一个元素的数组。
获取热门评论和最新评论demo code:
"raw": [
{
"blockName": "热门评论", //对于本api来说,这里不要改动,它操控了前端对block名的渲染
"cards": [
{ //这里数组每一个元素都是一条评论
"info": { //便于后端在拿到info的时候能在数据库中定位该消息(这里指评论消息)
"type": 5, //这里的5指评论,仅供参考,请后端确定真正的值,也可以是string
"id": 1
},
"content": "在公交车上站不动的老年人,免费发礼品时候都能冲刺", //评论文本
"imgs": [
""
], //评论最多有一个图片,由于本response是通用的,因此设计成数组,如果有图片则返回单元素数组,没有图片请返回null
"author": { //评论者信息
"id": 10048,
"avatar": "https://avatars2.githubusercontent.com/u/30586220?s=460&v=4",
"name": "Sakura坠"
},
"publishTime": "2018-08-26T15:15:04", //请返回类似该格式的时间(ISO8601标准时间格式)
"shareInfo":{"like": 365}, //点赞数
"footprint":{"like":true},
"replies": {
"count": 15, //该评论的回复数(对于回复的定义已写在前面)
"representatives": [
{ //注意,count大于等于2时最多两条
"author": { //回复者信息
"id": 10015,
"name": "怼图小姐姐扩列"
},
"content": "**大妈会让他们知道什么叫恐惧。。。真的。。。",
"imgs": null //回复也可以最多有一张图片
},
{
"author": {
"id": 10016,
"name": "我来说句公道话"
},
"content": "那些人还会觉得:既然免费送还花钱买,真傻。。这是一条超长评论这是一条超长评论这是一条超长评论这是一条超长评论",
"imgs": [
""
] //回复也可以最多有一张图片
}
]
} //下面的就不打那么多注释了,下面的注释是我写mock的时候敲的,可能会有纰漏,可以不予参考
},
{
"info": {
"type": 5,
"id": 1
},
"content": "在公交车上站不动的老年人,免费发礼品时候都能冲刺", //文本消息
"imgs": [
""
], //评论最多有一个图片
"author": {
"id": 10048,
"avatar": "https://avatars2.githubusercontent.com/u/30586220?s=460&v=4",
"name": "Sakura坠"
},
"publishTime": "2018-08-26T15:15:04",
"shareInfo":{"like": 365},
"footprint":{"like":true},
"replies": {
"count": 15,
"representatives": [
{ //count大于等于2时最多两条
"author": {
"id": 10015,
"name": "怼图小姐姐扩列"
},
"content": "**大妈会让他们知道什么叫恐惧。。。真的。。。",
"imgs": null
},
{
"author": {
"id": 10016,
"name": "我来说句公道话"
},
"content": "那些人还会觉得:既然免费送还花钱买,真傻。。",
"imgs": [
""
] //评论最多有一个图片
}
]
}
}
]
},
{ //这里是第二个block
"blockName": "最新评论",
"cards": [
{
"info": {
"type": 5,
"id": 1
},
"content": "在公交车上站不动的老年人,免费发礼品时候都能冲刺", //文本消息
"imgs": [
""
], //评论最多有一个图片
"author": {
"id": 10048,
"avatar": "https://avatars2.githubusercontent.com/u/30586220?s=460&v=4",
"name": "Sakura坠"
},
"publishTime": "2018-08-27T20:02:04",
"shareInfo":{"like": 12},
"footprint":{"like":true},
"replies": {
"count": 15,
"representatives": [
{ //count大于等于2时最多两条
"author": {
"id": 10015,
"name": "怼图小姐姐扩列"
},
"content": "**大妈会让他们知道什么叫恐惧。。。真的。。。",
"imgs": null
},
{
"author": {
"id": 10016,
"name": "我来说句公道话"
},
"content": "那些人还会觉得:既然免费送还花钱买,真傻。。这是一条超长评论这是一条超长评论这是一条超长评论这是一条超长评论",
"imgs": [
""
] //评论最多有一个图片
}
]
}
},
{
"info": {
"type": 5,
"id": 1
},
"content": "在公交车上站不动的老年人,免费发礼品时候都能冲刺", //文本消息
"imgs": [
""
], //评论最多有一个图片
"author": {
"id": 10048,
"avatar": "https://avatars2.githubusercontent.com/u/30586220?s=460&v=4",
"name": "Sakura坠"
},
"publishTime": "2018-08-27T19:15:04",
"shareInfo":{"like": 0},
"footprint":{"like":false},
"replies": {
"count": 15,
"representatives": [
{ //count大于等于2时最多两条
"author": {
"id": 10015,
"name": "怼图小姐姐扩列"
},
"content": "**大妈会让他们知道什么叫恐惧。。。真的。。。",
"imgs": null
},
{
"author": {
"id": 10016,
"name": "我来说句公道话"
},
"content": "那些人还会觉得:既然免费送还花钱买,真傻。。",
"imgs": [
""
] //评论最多有一个图片
}
]
}
}
]
}
]
更新列表(获取更多最新评论)demo code:
raw: [{//第一个block,可以注意到cards为空数组,也可以返回一个null,请注意对比request
blockName: '热门评论',//对于本api来说,这里不要改动,它操控了前端对block名的渲染
cards: []
}, {//这里是第二个block
blockName: '最新评论',
cards: [{
info: {
type: 5,
id: 1
},
content: "在公交车上站不动的老年人,免费发礼品时候都能冲刺",//文本消息
imgs: [""],//评论最多有一个图片
author: {
id: 10048,
avatar: "https://avatars2.githubusercontent.com/u/30586220?s=460&v=4",
name: "Sakura坠"
},
publishTime: "2018-08-27T20:02:04",
shareInfo:{like: 2},
footprint:{like:true},
replies: {
count: 15,
representatives: [{//count大于等于2时最多两条
author: {
id: 10015,
name: "怼图小姐姐扩列"
},
content: "**大妈会让他们知道什么叫恐惧。。。真的。。。",
imgs: null
}, {
author: {
id: 10016,
name: "我来说句公道话"
},
content: "那些人还会觉得:既然免费送还花钱买,真傻。。这是一条超长评论这是一条超长评论这是一条超长评论这是一条超长评论",
imgs: [""]//评论最多有一个图片
}]
}
}, {
info: {
type: 5,
id: 1
},
content: "在公交车上站不动的老年人,免费发礼品时候都能冲刺",//文本消息
imgs: [""],//评论最多有一个图片
author: {
id: 10048,
avatar: "https://avatars2.githubusercontent.com/u/30586220?s=460&v=4",
name: "Sakura坠"
},
publishTime: "2018-08-27T19:15:04",
shareInfo:{like: 0}
footprint:{like:false},
replies: {
count: 15,
representatives: [{//count大于等于2时最多两条
author: {
id: 10015,
name: "怼图小姐姐扩列"
},
content: "**大妈会让他们知道什么叫恐惧。。。真的。。。",
imgs: null
}, {
author: {
id: 10016,
name: "我来说句公道话"
},
content: "那些人还会觉得:既然免费送还花钱买,真傻。。",
imgs: [""]//评论最多有一个图片
}]
}
}]
}]
获取回复列表api
该api用于获取某个评论的回复列表。
注意,评论这一层下面有一层回复,也就是说,回复是对评论的评论,回复是最底层,叶子结点,没有回复的回复这种说法。
request
{
type:0,//假设0对应新闻
id:10001,//我要获取id为10001这条新闻的评论列表
page:1,
limit:[20]//这里注意使用数组
}
response
注意,response有个特点,它的格式是通用的,raw是一个数组,我们可以看到app里面点开详情查看评论的时候分为两个block,一个是热门评论,一个是最新评论,那么对应的raw就是一个两个元素的数组。
而点进一条评论的详情,我们可以看到只有一个block,那么这时候response返回的raw就是一个包含一个元素的数组。
demo code:
raw: [{//仅包含一个元素的数组
blockName: '全部回复',//对于本api来说这里不要改动
cards: [{//每条回复的内容
info: {//便于后端拿到info后可以直接定位到这条消息(在这里指回复消息)
type: 6,//假设6代表回复,这个后端决定,甚至可以是string
id: 1
},
content: "我女朋友就把我打肿了 女孩子都不会怜香惜玉吗╭(╯^╰)╮",//回复文本
imgs: [""],//回复最多有一个图片
author: {//回复的发布者信息
id: 10048,
avatar: "https://avatars2.githubusercontent.com/u/30762708?s=460&v=4",
name: "萌萌哒小巨兽"
},
publishTime: "2018-08-26T15:15:04",//请返回类似该格式的时间(ISO8601标准时间格式)
shareInfo:{like: 0},//点赞数
footprint:{like: false}
},{
info: {
type: 6,
id: 1
},
content: "我女朋友就把我打肿了 女孩子都不会怜香惜玉吗╭(╯^╰)╮",//回复文本
imgs: [""],//回复最多有一个图片
author: {
id: 10048,
avatar: "https://avatars2.githubusercontent.com/u/30762708?s=460&v=4",
name: "萌萌哒小巨兽"
},
publishTime: "2018-08-26T15:15:04",
shareInfo:{like: 0},//点赞数
footprint:{like: false}
},{
info: {
type: 6,
id: 1
},
content: "我女朋友就把我打肿了 女孩子都不会怜香惜玉吗╭(╯^╰)╮",//回复文本
imgs: [""],//回复最多有一个图片
author: {
id: 10048,
avatar: "https://avatars2.githubusercontent.com/u/30762708?s=460&v=4",
name: "萌萌哒小巨兽"
},
publishTime: "2018-08-26T15:15:04",
shareInfo:{like: 0},//点赞数
footprint:{like: false}
}]
}]
该api用于获取新闻列表,暂时没有设置条件的参数,比如说限定主题(对新闻而言则是分类标签),请按时间排序后(最近的位于最上)返回。
{
page:1,
pageSize:20
}
cards: [{
info: {//保存用于数据库检索的信息,方便后端在接收到该info之后可以在数据库定位这条消息
type: 0,//假设新闻这个表对应type为0,或者这里是个string也可以,后端决定
id: 1,//表中的id,或者为string也可以,后端决定
},
topic: {//新闻的分类、标签
id: 1,//标签id
name: "社团公众活动"//标签名
},
content: "筹集爱心,救助流浪猫咪!我们联合流浪猫救助站,做了一次宠物爱心公益。你在这里留下的每一个足记,都有可能挽救一只待哺的流浪猫咪!",//爬取的新闻可以直接定义为新闻标题
author: {
id: 10001,//发布者的id,可以为string,后端决定,爬取的新闻请为每个站点注册个用户,比如说熟知网
avatar: "https://avatars2.githubusercontent.com/u/30586220?s=460&v=4",//发布者头像url
name: "Message广场导游"//发布者名称
},
extraInfo: "官方新闻",//这个是位于右上角的tip,建议爬取的新闻这里写官方新闻
publishTime:"2018-08-26T15:15:04", //请返回类似该格式的时间(ISO8601标准时间格式)
shareInfo: {//点赞数,评论数,分享数
like: 5348,
comment: 221,
share: 149
},
media:{
type:"url",
title:"",//新闻标题,若无标题请置null
url:""//爬取的新闻请将原新闻url写在这里
},
footprint:{//如果这个人把赞撤了或者把评论删了或者把转发的消息删了,就是false了
like:true,//点了赞
comment:true,//评了论
forward:true//转了发
}
}]
关于上述media:
用户要么发链接,要么发图片,链接只能一条,图片可以三张
//链接
media:{
type:"url",
title:"",//新闻标题,若无标题请置null
url:""//爬取的新闻请将原新闻url写在这里
}
//图片
media:{
type:"img",
imgs:["",""]//最多3张
}
该api对于新闻、动态、评论、回复等消息都是通用的
{
type:0,//新闻、动态、评论还是回复
id:10001,//对应类型的id
like:true//false为取消点赞
}
{
code:"SUCCESS",
message:null,
data:null
}
由于前端使用iframe打开跨域页面,一些web服务器response头含有X-Frame-Options,导致iframe无法正确显示内容,前端攻城狮已经因为这个血拼一整天了,只好想此拙计:
默认使用iframeForward进行reverse-proxy,当iframeForward发现该站点response没有X-Frame-Options头时,会调用”添加iframe支持站点“API请求后端接口。这种方法兼容性较好,但无法处理跨域xhr,除非对返回的内容进行侵入性修改,这不是我们想要的,而且反向代理会消耗服务器网络资源,所以我们得尽量少地使用这种方法。
之后会fork一个iframeForward项目到Actooors里来,做一个针对项目的适配。
前端在使用iframe打开跨域页面时,先查询要访问的站点是否属于iframe支持站点,若属于,则直接访问
由于X-Frame-Options头是一种安全措施,不可否认一些站点可能会在将来加入这个措施,因此我们需要一种办法检测站点是否需要移除iframe支持站点,由此来更新iframe支持站点的数据库列表。
在前端调用查询iframe支持站点api时,后端应当返回一个布尔值,用来标识该站点是否支持iframe,如果支持,前端则直接渲染,如果不支持,则改由iframeForward进行反向代理。
后端应当在该站点支持iframe时,以一定的概率仍然返回false,即让前端误以为不支持iframe,从而由iframeForward进行反代,反代会检测response中的X-Frame-Options属性,决定数据库是否更新。
概率由服务器压力决定,默认设为0.1。
不存在则添加,存在则更新
{
host:"http://www.lib.shu.edu.cn",
support: true
}
{
host:"http://www.lib.shu.edu.cn",
support: false//此时需要从表中删除该项
}
{
host:"http://www.lib.shu.edu.cn"
}
{
code:"SUCCESS",
message:null,
data:{
exist:true
}
}
https://developer.qiniu.com/kodo/api/1312/upload
客户端上传前需要先从服务端获取上传凭证,并在上传资源时将上传凭证作为请求内容的一部分。不带凭证或带非法凭证的请求将返回 HTTP 错误码 401,代表认证失败。
https://developer.qiniu.com/kodo/manual/1208/upload-token
{
type:0,
id:101
}
返回对应类型的单个消息,具体请查看之前的issue
请附带token
http://localhost:8188/api/news/interestNews?wd=hwiwtpmzkkrcprflftyo
get
{
"code": "SUCCESS",
"message": null,
"data": {
"sendTime": "2019-03-27T12:07:26.000+0800",
"cards": [
{
"info": {
"type": 0,
"id": 174
},
"topic": {
"name": "通知公告",
"id": 2
},
"content": "上海大学2019年春季招生预录取候补资格考生名单公示",
"author": {
"id": "2",
"avatar": "https://avatars2.githubusercontent.com/u/30586220?s=460&v=4",
"name": "本科招生网"
},
"extraInfo": "官方新闻",
"publishTime": "2019-03-27T16:38:55.000+0800",
"shareInfo": {
"share": 0,
"like": 1233,
"comment": 0
},
"media": {
"type": "url",
"value": "http://bkzsw.shu.edu.cn/info/1030/6689.htm",
"title": "上海大学2019年春季招生预录取候补资格考生名单公示"
},
"footprint": {
"forward": false,
"like": false,
"comment": false
}
},
{
"info": {
"type": 0,
"id": 5
},
"topic": {
"name": "资源动态",
"id": 1
},
"content": "《文博党建小课堂》开通试用",
"author": {
"id": "1",
"avatar": "https://avatars2.githubusercontent.com/u/30586220?s=460&v=4",
"name": "图书馆"
},
"extraInfo": "官方新闻",
"publishTime": "2019-03-27T14:44:29.000+0800",
"shareInfo": {
"share": 0,
"like": 46,
"comment": 0
},
"media": {
"type": "url",
"value": "http://www.lib.shu.edu.cn/node/1092",
"title": "《文博党建小课堂》开通试用"
},
"footprint": {
"forward": false,
"like": false,
"comment": false
}
},
{
"info": {
"type": 0,
"id": 8
},
"topic": {
"name": "资源动态",
"id": 1
},
"content": "哈佛燕京图书馆中文善本特藏数字化免费开放使用",
"author": {
"id": "1",
"avatar": "https://avatars2.githubusercontent.com/u/30586220?s=460&v=4",
"name": "图书馆"
},
"extraInfo": "官方新闻",
"publishTime": "2019-03-27T14:44:28.000+0800",
"shareInfo": {
"share": 0,
"like": 23,
"comment": 13
},
"media": {
"type": "url",
"value": "http://www.lib.shu.edu.cn/node/1104",
"title": "哈佛燕京图书馆中文善本特藏数字化免费开放使用"
},
"footprint": {
"forward": false,
"like": false,
"comment": false
}
},
{
"info": {
"type": 0,
"id": 9
},
"topic": {
"name": "资源动态",
"id": 1
},
"content": "文博行业知识资源库开通试用",
"author": {
"id": "1",
"avatar": "https://avatars2.githubusercontent.com/u/30586220?s=460&v=4",
"name": "图书馆"
},
"extraInfo": "官方新闻",
"publishTime": "2019-03-27T16:38:06.000+0800",
"shareInfo": {
"share": 0,
"like": 12,
"comment": 11
},
"media": {
"type": "url",
"value": "http://www.lib.shu.edu.cn/node/1093",
"title": "文博行业知识资源库开通试用"
},
"footprint": {
"forward": false,
"like": false,
"comment": false
}
},
{
"info": {
"type": 0,
"id": 10
},
"topic": {
"name": "资源动态",
"id": 1
},
"content": "东京审判文献数据库开通试用",
"author": {
"id": "1",
"avatar": "https://avatars2.githubusercontent.com/u/30586220?s=460&v=4",
"name": "图书馆"
},
"extraInfo": "官方新闻",
"publishTime": "2019-03-27T14:44:28.000+0800",
"shareInfo": {
"share": 0,
"like": 12,
"comment": 0
},
"media": {
"type": "url",
"value": "http://www.lib.shu.edu.cn/node/1068",
"title": "东京审判文献数据库开通试用"
},
"footprint": {
"forward": false,
"like": false,
"comment": false
}
}
],
"nums": 5
}
}
该api对新闻、动态进行评论,或者对评论进行回复,或者对回复进行回复
对新闻、动态进行评论:
{
type:0,//假设0对应新闻
id:10001,//我要给id为10001这条新闻评论
content:"哈哈哈哈红红火火恍恍惚惚加油啊韩红和韩寒嘿嘿嘿韩寒喊韩红坏坏",
img:"https://gss2.bdstatic.com/-fo3dSag_xI4khGkpoWK1HF6hhy/baike/w%3D268/sign=6cad1cbee0c4b7453494b010f7fe1e78/a8014c086e061d956c83adaf70f40ad163d9ca64.jpg" //评论最多一张图片
}
对评论进行回复:
{
type:5,//假设5对应评论
id:11,//我要给id为11这条评论回复
content:"哈哈哈哈红红火火恍恍惚惚加油啊韩红和韩寒嘿嘿嘿韩寒喊韩红坏坏",
img:"https://gss2.bdstatic.com/-fo3dSag_xI4khGkpoWK1HF6hhy/baike/w%3D268/sign=6cad1cbee0c4b7453494b010f7fe1e78/a8014c086e061d956c83adaf70f40ad163d9ca64.jpg" //回复最多一张图片
}
对回复进行回复,实则是对评论进行回复的一种特殊情况,消息要同时通知被评论方和被回复方,可以按照我只是在回复这个评论的时候“@了某人”进行理解,但是建议在数据库记录他@的某个消息的id以及那个人的id:
{
type:5,//假设5对应评论
id:11,//评论的id,我要回复的回复位于该评论之下
replyId:4,//要回复的回复id
content:"哈哈哈哈红红火火恍恍惚惚加油啊韩红和韩寒嘿嘿嘿韩寒喊韩红坏坏",
img:"https://gss2.bdstatic.com/-fo3dSag_xI4khGkpoWK1HF6hhy/baike/w%3D268/sign=6cad1cbee0c4b7453494b010f7fe1e78/a8014c086e061d956c83adaf70f40ad163d9ca64.jpg" //评论最多一张图片
}
{
code:"SUCCESS",
message:null,
data:null
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.