图片自动上传,代码测试编译错误过长。

This commit is contained in:
yuanke 2016-05-13 08:38:28 +08:00
parent 5180fdab39
commit a39702f962
5 changed files with 90 additions and 46 deletions

View File

@ -40,8 +40,6 @@ gem 'kaminari'
gem 'elasticsearch-model'
gem 'elasticsearch-rails'
gem 'certified'
group :development do
gem 'grape-swagger'
gem 'better_errors', '~> 1.1.0'

View File

@ -123,6 +123,7 @@ class StudentWorkController < ApplicationController
#-1 默认值 0全部正确并结束 2 超时 -2 编译错误
resultObj[:status] = -1
resultObj[:results] = result["results"].first #本次测试结果
result["error_msg"] = result["error_msg"][0..1023]
resultObj[:error_msg] = result["error_msg"] #编译错误时的信息
#该状态用于存入CodeTests

View File

@ -145,11 +145,11 @@ class Kindeditor::AssetsController < ApplicationController
Dir.mkdir(dirPath+dirDate)
end
fileStr = []
fileStr = ""
picArry.each_with_index do |picUrl,index|
imgBaseName = File.basename(picUrl)
tmpImgType = imgBaseName.split(".").last[0..2]
tmpImgType = imgBaseName.split(".").last.split("?")[0]
# 仅支持如下图片格式:bmp,jpeg,jpg,png,gif,BMP,JPEG,JPG,PNG,GIF
fileType = tmpImgType.match("gif|jpg|jpeg|png|bmp|BMP|JPEG|JPG|PNG|GIF")
@ -161,10 +161,13 @@ class Kindeditor::AssetsController < ApplicationController
fileDir = dirPath + dirDate + "/"+fileName
#重点!!
File.open(fileDir,'wb'){ |f| f.write(open(picUrl).read) }
fileDir = fileDir.split("public")[1]
fileStr = filedir + "|"
begin
File.open(fileDir,'wb'){ |f| f.write(open(picUrl).read) }
fileDir = fileDir.split("public")[1]
rescue
fileDir = picUrl
end
fileStr = fileStr+fileDir + "|"
end
render :text =>fileStr
end

View File

@ -5993,10 +5993,24 @@ _plugin('core', function(K) {
html = html.replace(/\n/g, '<br />$&');
}
}
self.insertHtml(html, true);
df();
// $("#ajax-indicator").hide();
// var kePasteContainer = document.getElementById("ke_paste");
// if (kePasteContainer == null) {
// kePasteContainer = document.createElement("div");
// kePasteContainer.id = "ke_paste";
// var last=document.body.lastChild;//得到页面的最后个元素
// document.body.insertBefore(kePasteContainer,last);//在得到的最后元素之前插入
// }
// kePasteContainer.innerHTML = html;
// $("#ke_paste").hide();
//
// var imglist = $("#ke_paste").find("img");
//
// if (imglist.length > 0){
// df(self);
// }
self.insertHtml(html, true);
df(self);
}
K(doc.body).bind('paste', function(e){
if (self.pasteType === 0) {

View File

@ -1,8 +1,8 @@
// Generated by CoffeeScript 1.9.0
/*
paste.js is an interface to read data ( text / image ) from clipboard in different browsers. It also contains several hacks.
https://github.com/layerssss/paste.js
paste.js is an interface to read data ( text / image ) from clipboard in different browsers. It also contains several hacks.
https://github.com/layerssss/paste.js
*/
(function() {
@ -279,7 +279,7 @@ https://github.com/layerssss/paste.js
}
//firefox问题处理因为采用了 pastableContenteditable 模式,故只需要删除默认的粘贴
if ($(img).attr('src').startsWith('data:image/')) {
_results.push($(img).remove());
_results.push($(img).remove());
};
}
return _results;
@ -307,23 +307,23 @@ function enablePasteImg(_editor) {
$(nodeBody).pastableContenteditable();
dataURItoBlob = function(dataURI) {
// convert base64/URLEncoded data component to raw binary data held in a string
var byteString;
if (dataURI.split(',')[0].indexOf('base64') >= 0)
byteString = atob(dataURI.split(',')[1]);
else
byteString = unescape(dataURI.split(',')[1]);
// convert base64/URLEncoded data component to raw binary data held in a string
var byteString;
if (dataURI.split(',')[0].indexOf('base64') >= 0)
byteString = atob(dataURI.split(',')[1]);
else
byteString = unescape(dataURI.split(',')[1]);
// separate out the mime component
var mimeString = dataURI.split(',')[0].split(':')[1].split(';')[0];
// separate out the mime component
var mimeString = dataURI.split(',')[0].split(':')[1].split(';')[0];
// write the bytes of the string to a typed array
var ia = new Uint8Array(byteString.length);
for (var i = 0; i < byteString.length; i++) {
ia[i] = byteString.charCodeAt(i);
}
// write the bytes of the string to a typed array
var ia = new Uint8Array(byteString.length);
for (var i = 0; i < byteString.length; i++) {
ia[i] = byteString.charCodeAt(i);
}
return new Blob([ia], {type:mimeString});
return new Blob([ia], {type:mimeString});
};
$(nodeBody).on('pasteImage', function(ev, data) {
@ -337,15 +337,15 @@ function enablePasteImg(_editor) {
data.append("imgFile",blob, "imageFilename.png");
console.log(data);
$.ajax({
url: '/kindeditor/upload?dir=image',
contentType: false,
type: 'POST',
data: data,
processData: false,
success: function(data) {
console.log(data);
editor.exec('insertimage', JSON.parse(data).url);
}
url: '/kindeditor/upload?dir=image',
contentType: false,
type: 'POST',
data: data,
processData: false,
success: function(data) {
console.log(data);
editor.exec('insertimage', JSON.parse(data).url);
}
});
}
@ -353,8 +353,11 @@ function enablePasteImg(_editor) {
return;
};
function df() {
var img = $(".ke-edit-iframe").contents().find("img");
//复制粘贴时把远程图片上传到服务器
function df(myself) {
// var img = $("#ke_paste").find("img");
var currele = document.activeElement;
var img = $(currele).contents().find("img");
var piccount = 0;
var sstr = "";
$(img).each(function (i) {
@ -367,24 +370,42 @@ function df() {
sstr += that.attr("src") + "|";
}
});
uploadpic(sstr);
uploadpic(sstr,myself);
}
function uploadpic(piclist) {
function keShadow(myself)
{
var keShadowContainer = document.getElementById("ke_shadow");
if (keShadowContainer == null) {
keShadowContainer = document.createElement("div");
keShadowContainer.id = "ke_shadow";
keShadowContainer.innerHTML = "<div class='ui-widget-overlay' z-index: 1001;'></div>";
$("#ajax-modal").after(keShadowContainer);
}
var tWidth = document.body.scrollWidth;
var tHeight = document.body.scrollHeight;
$(".ui-widget-overlay").css("width", tWidth);
$(".ui-widget-overlay").css("height", tHeight);
$("#ke_shadow").show();
myself.readonly();
}
function uploadpic(piclist,myself) {
if (piclist.length == 0) return false;
$.ajax({
url: "/kindeditor/uploadpic",
data: "pic=" + piclist,
data:{"pic":piclist},
type: "GET",
beforeSend: function () {
$("#ajax-indicator").text("图片上传中请稍等...");
// $("#ajax-indicator span").text("图片上传中请稍等...");
keShadow(myself);
},
success: function (msg) {
if (msg !== "") {
var str = new Array();
str = msg.split('|');
var img = $(".ke-edit-iframe").contents().find("img");
var currele = document.activeElement;
var img = $(currele).contents().find("img");
var tIndex = 0;
$(img).each(function (i) {
var that = $(this);
@ -397,8 +418,15 @@ function uploadpic(piclist) {
}
});
}
// else $("#confirm").text("上传失败!");
// $("#ajax-indicator span").text("载入中...");
$("#ke_shadow").hide();
myself.readonly(false);
}
}).fail(function(xhr, status){
// $("#ajax-indicator span").text("载入中...");
$("#ke_shadow").hide();
myself.readonly(false);
return;
});
}