Browse Source

提交代码。

Signed-off-by: zouap <zouap@pcl.ac.cn>
tags/v1.22.1.1^2
zouap 3 years ago
parent
commit
ed19ec4ad9
2 changed files with 51 additions and 10 deletions
  1. +46
    -8
      public/home/home.js
  2. +5
    -2
      routers/actionnotification.go

+ 46
- 8
public/home/home.js View File

@@ -1,15 +1,15 @@


var output = document.getElementById("newmessage");
var socket = new WebSocket("ws://" + document.location.host + "/action/notification");
var output = document.getElementById("newmessage");
var socket = new WebSocket("ws://" + document.location.host + "/action/notification");


socket.onopen = function () {
socket.onopen = function () {
console.log("message has connected."); console.log("message has connected.");
};
};


var messageQueue = [];
var maxSize = 10;
var messageQueue = [];
var maxSize = 10;


socket.onmessage = function (e) {
socket.onmessage = function (e) {
console.log("data=" + e.data) console.log("data=" + e.data)
var data =JSON.parse(e.data) var data =JSON.parse(e.data)
var html = ""; var html = "";
@@ -40,5 +40,43 @@


} }
output.innerHTML = html output.innerHTML = html
};
};


queryRecommendData();

function queryRecommendData(){
$.ajax({
type:"GET",
url:"/recommend/org",
headers: {
authorization:token,
},
dataType:"json",
async:false,
success:function(json){
console.log(json);

},
error:function(response) {
console.log(response);
}
});

$.ajax({
type:"GET",
url:"/recommend/repo",
headers: {
authorization:token,
},
dataType:"json",
async:false,
success:function(json){
console.log(json);
},
error:function(response) {
console.log(response);
}
});

}

+ 5
- 2
routers/actionnotification.go View File

@@ -1,6 +1,8 @@
package routers package routers


import ( import (
"net/http"

"code.gitea.io/gitea/models" "code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
@@ -11,6 +13,9 @@ import (
var upgrader = websocket.Upgrader{ var upgrader = websocket.Upgrader{
ReadBufferSize: 1024, ReadBufferSize: 1024,
WriteBufferSize: 1024, WriteBufferSize: 1024,
CheckOrigin: func(r *http.Request) bool {
return true
},
} }


var SocketManager = socketwrap.NewClientsManager() var SocketManager = socketwrap.NewClientsManager()
@@ -49,5 +54,3 @@ func WriteLastTenActionsIfHave(conn *websocket.Conn) {
} }
socketwrap.LastTenActionsQueue.Mutex.RUnlock() socketwrap.LastTenActionsQueue.Mutex.RUnlock()
} }



Loading…
Cancel
Save