1
0
Fork 0
mirror of https://gitlab.com/Shinobi-Systems/ShinobiCE.git synced 2025-03-09 15:40:15 +00:00
This commit is contained in:
Moe 2019-10-26 13:34:02 -07:00
parent ef40f3f231
commit 167603dfb0
118 changed files with 16152 additions and 5441 deletions

View file

@ -34,8 +34,6 @@ module.exports = function(s,config,lang){
userDetails.whcs_accessKeyId !== ''&&
userDetails.whcs_secretAccessKey &&
userDetails.whcs_secretAccessKey !== ''&&
userDetails.whcs_region &&
userDetails.whcs_region !== ''&&
userDetails.whcs_bucket !== ''
){
if(!userDetails.whcs_dir || userDetails.whcs_dir === '/'){
@ -50,6 +48,10 @@ module.exports = function(s,config,lang){
if(!userDetails.whcs_endpoint || userDetails.whcs_endpoint === ''){
userDetails.whcs_endpoint = 's3.wasabisys.com'
}
var whcs_region = null
if(userDetails.whcs_region && userDetails.whcs_region !== ''){
whcs_region = userDetails.whcs_region
}
var endpointSplit = userDetails.whcs_endpoint.split('.')
if(endpointSplit.length > 2){
endpointSplit.shift()
@ -62,7 +64,7 @@ module.exports = function(s,config,lang){
endpoint: wasabiEndpoint,
accessKeyId: userDetails.whcs_accessKeyId,
secretAccessKey: userDetails.whcs_secretAccessKey,
region: userDetails.whcs_region
region: whcs_region
})
s.group[e.ke].whcs = new s.group[e.ke].whcs.S3();
}
@ -100,9 +102,10 @@ module.exports = function(s,config,lang){
fileStream.on('error', function (err) {
console.error(err)
})
var bucketName = s.group[e.ke].init.whcs_bucket
var saveLocation = s.group[e.ke].init.whcs_dir+e.ke+'/'+e.mid+'/'+k.filename
s.group[e.ke].whcs.upload({
Bucket: s.group[e.ke].init.whcs_bucket,
Bucket: bucketName,
Key: saveLocation,
Body:fileStream,
ACL:'public-read',
@ -112,6 +115,8 @@ module.exports = function(s,config,lang){
s.userLog(e,{type:lang['Wasabi Hot Cloud Storage Upload Error'],msg:err})
}
if(s.group[e.ke].init.whcs_log === '1' && data && data.Location){
var cloudLink = data.Location
cloudLink = fixCloudianUrl(e,cloudLink)
var save = [
e.mid,
e.ke,
@ -123,7 +128,7 @@ module.exports = function(s,config,lang){
}),
k.filesize,
k.endTime,
data.Location
cloudLink
]
s.sqlQuery('INSERT INTO `Cloud Videos` (mid,ke,time,status,details,size,end,href) VALUES (?,?,?,?,?,?,?,?)',save)
s.setCloudDiskUsedForGroup(e,{
@ -135,6 +140,83 @@ module.exports = function(s,config,lang){
})
}
}
var onInsertTimelapseFrame = function(monitorObject,queryInfo,filePath){
var e = monitorObject
if(s.group[e.ke].whcs && s.group[e.ke].init.use_whcs !== '0' && s.group[e.ke].init.whcs_save === '1'){
var fileStream = fs.createReadStream(filePath)
fileStream.on('error', function (err) {
console.error(err)
})
var saveLocation = s.group[e.ke].init.whcs_dir + e.ke + '/' + e.mid + '_timelapse/' + queryInfo.filename
s.group[e.ke].whcs.upload({
Bucket: s.group[e.ke].init.whcs_bucket,
Key: saveLocation,
Body: fileStream,
ACL:'public-read',
ContentType:'image/jpeg'
},function(err,data){
if(err){
s.userLog(e,{type:lang['Wasabi Hot Cloud Storage Upload Error'],msg:err})
}
if(s.group[e.ke].init.whcs_log === '1' && data && data.Location){
var save = [
queryInfo.mid,
queryInfo.ke,
queryInfo.time,
s.s({
type : 'whcs',
location : saveLocation,
}),
queryInfo.size,
data.Location
]
s.sqlQuery('INSERT INTO `Cloud Timelapse Frames` (mid,ke,time,details,size,href) VALUES (?,?,?,?,?,?)',save)
s.setCloudDiskUsedForGroup(e,{
amount : s.kilobyteToMegabyte(queryInfo.size),
storageType : 'whcs'
},'timelapseFrames')
s.purgeCloudDiskForGroup(e,'whcs','timelapseFrames')
}
})
}
}
var onDeleteTimelapseFrameFromCloud = function(e,frame,callback){
// e = user
try{
var frameDetails = JSON.parse(frame.details)
}catch(err){
var frameDetails = frame.details
}
if(frameDetails.type !== 'whcs'){
return
}
if(!frameDetails.location){
frameDetails.location = frame.href.split(locationUrl)[1]
}
s.group[e.ke].whcs.deleteObject({
Bucket: s.group[e.ke].init.whcs_bucket,
Key: frameDetails.location,
}, function(err, data) {
if (err) console.log(err);
callback()
});
}
var fixCloudianUrl = function(e,cloudLink){
if(cloudLink.indexOf('http') === -1){
var bucketName = s.group[e.ke].init.whcs_bucket
var endPointSplit = s.group[e.ke].init.whcs_endpoint.split('://')
endPoint = endPointSplit[1] || endPointSplit[0]
var protocol = `https`
if(endPointSplit[1])protocol = endPointSplit[0]
var cloudLinkPrefix = `${protocol}://${bucketName}.${endPoint}`
var truncatedLink = cloudLink.substring(0, bucketName.length + 3)
if(truncatedLink.indexOf(`${bucketName}/`) > -1){
cloudLink = cloudLink.replace(`${bucketName}/`,'')
}
cloudLink = s.checkCorrectPathEnding(cloudLinkPrefix) + cloudLink
}
return cloudLink
}
//wasabi
s.addCloudUploader({
name: 'whcs',
@ -145,5 +227,250 @@ module.exports = function(s,config,lang){
cloudDiskUseStartupExtensions: cloudDiskUseStartupForWasabiHotCloudStorage,
beforeAccountSave: beforeAccountSaveForWasabiHotCloudStorage,
onAccountSave: cloudDiskUseStartupForWasabiHotCloudStorage,
onInsertTimelapseFrame: onInsertTimelapseFrame,
onDeleteTimelapseFrameFromCloud: onDeleteTimelapseFrameFromCloud
})
return {
"evaluation": "details.use_whcs !== '0'",
"name": lang["S3-Based Network Storage"],
"color": "forestgreen",
"info": [
{
"name": "detail=whcs_save",
"selector":"autosave_whcs",
"field": lang.Autosave,
"description": "",
"default": lang.No,
"example": "",
"fieldType": "select",
"possible": [
{
"name": lang.No,
"value": "0"
},
{
"name": lang.Yes,
"value": "1"
}
]
},
{
"hidden": true,
"name": "detail=use_whcs_endpoint_select",
"selector":"h_whcs_endpoint",
"field": lang.Endpoint,
"description": "",
"default": "",
"example": "",
"fieldType": "select",
"possible": [
{
"name": "Custom Endpoint",
"value": ""
},
{
"name": lang['Wasabi Hot Cloud Storage'],
"value": "s3.wasabisys.com"
}
]
},
{
"hidden": true,
"field": lang['Endpoint Address'],
"name": "detail=whcs_endpoint",
"placeholder": "s3.wasabisys.com",
"form-group-class": "autosave_whcs_input autosave_whcs_1",
"form-group-class-pre-layer":"h_whcs_endpoint_input h_whcs_endpoint_",
"description": "",
"default": "",
"example": "",
"possible": ""
},
{
"hidden": true,
"field": lang.Bucket,
"name": "detail=whcs_bucket",
"placeholder": "Example : slippery-seal",
"form-group-class": "autosave_whcs_input autosave_whcs_1",
"description": "",
"default": "",
"example": "",
"possible": ""
},
{
"hidden": true,
"field": lang.aws_accessKeyId,
"name": "detail=whcs_accessKeyId",
"form-group-class": "autosave_whcs_input autosave_whcs_1",
"description": "",
"default": "",
"example": "",
"possible": ""
},
{
"hidden": true,
"name": "detail=whcs_secretAccessKey",
"fieldType":"password",
"placeholder": "",
"field": lang.aws_secretAccessKey,
"form-group-class":"autosave_whcs_input autosave_whcs_1",
"description": "",
"default": "",
"example": "",
"possible": ""
},
{
"hidden": true,
"name": "detail=whcs_region",
"field": lang.Region,
"fieldType": "select",
"form-group-class":"autosave_whcs_input autosave_whcs_1",
"description": "",
"default": "",
"example": "",
"possible": [
{
"name": lang['No Region'],
"value": ""
},
{
"name": "US West 1",
"value": "us-west-1"
},
{
"name": "US West 2)",
"value": "us-west-2"
},
{
"name": "US East 1",
"value": "us-east-2"
},
{
"name": "US East 2",
"value": "us-east-1"
},
{
"name": "Asia Pacific 1",
"value": "ap-south-1"
},
{
"name": "Asia Pacific 2",
"value": "ap-northeast-2"
},
{
"name": "Asia Pacific 3",
"value": "ap-northeast-3"
},
{
"name": "Asia Pacific 4",
"value": "ap-southeast-1"
},
{
"name": "Asia Pacific 5",
"value": "ap-southeast-2"
},
{
"name": "Asia Pacific 6",
"value": "ap-northeast-1"
},
{
"name": "Canada 1",
"value": "ca-central-1"
},
{
"name": "China 1",
"value": "cn-north-1"
},
{
"name": "China 1",
"value": "cn-northwest-1"
},
{
"name": "EU 1",
"value": "eu-central-1"
},
{
"name": "EU 2",
"value": "eu-west-1"
},
{
"name": "EU 3",
"value": "eu-west-2"
},
{
"name": "EU 4",
"value": "eu-west-3"
},
{
"name": "South America 1",
"value": "sa-east-1"
}
]
},
{
"hidden": true,
"name": "detail=whcs_log",
"field": lang['Save Links to Database'],
"fieldType": "select",
"selector": "h_whcssld",
"form-group-class":"autosave_whcs_input autosave_whcs_1",
"description": "",
"default": "",
"example": "",
"possible": [
{
"name": lang.No,
"value": "0"
},
{
"name": lang.Yes,
"value": "1"
}
]
},
{
"hidden": true,
"name": "detail=use_whcs_size_limit",
"field": lang['Use Max Storage Amount'],
"fieldType": "select",
"selector": "h_whcszl",
"form-group-class":"autosave_whcs_input autosave_whcs_1",
"form-group-class-pre-layer":"h_whcssld_input h_whcssld_1",
"description": "",
"default": "",
"example": "",
"possible": [
{
"name": lang.No,
"value": "0"
},
{
"name": lang.Yes,
"value": "1"
}
]
},
{
"hidden": true,
"name": "detail=whcs_size_limit",
"field": lang['Max Storage Amount'],
"form-group-class":"autosave_whcs_input autosave_whcs_1",
"form-group-class-pre-layer":"h_whcssld_input h_whcssld_1",
"description": "",
"default": "10000",
"example": "",
"possible": ""
},
{
"hidden": true,
"name": "detail=whcs_dir",
"field": lang['Save Directory'],
"form-group-class":"autosave_whcs_input autosave_whcs_1",
"description": "",
"default": "/",
"example": "",
"possible": ""
},
]
}
}