mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-09 10:34:17 +00:00
ycore.ng_comty & rs_cloud => API_CALL
This commit is contained in:
parent
1c284e0070
commit
cc00d36f14
@ -1,8 +1,8 @@
|
||||
// List of modules uploaded to yCore
|
||||
// List of modules used for this app
|
||||
export * from './libs/comty_ng/pre.js';
|
||||
export * from './libs/yulio_id/pre.js';
|
||||
export * from './libs/ycore_styles/pre.js';
|
||||
export * from './libs/ycore_sdcp/pre.js';
|
||||
export * from './libs/app_functions/pre.js'
|
||||
|
||||
export * from './libs/rs_cloud/pre.js'
|
||||
|
||||
|
@ -1,9 +1,7 @@
|
||||
import * as ycore from 'ycore'
|
||||
var jquery = require("jquery");
|
||||
import * as Icons from '@ant-design/icons'
|
||||
import { RenderFeed } from 'components/MainFeed'
|
||||
|
||||
|
||||
export const FeedHandler = {
|
||||
refresh: () => {
|
||||
RenderFeed.RefreshFeed()
|
||||
@ -34,373 +32,226 @@ export const IsThisPost = {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
export const Post_Comments = {
|
||||
delete: (callback, payload) => {
|
||||
if (!payload) {
|
||||
return false
|
||||
}
|
||||
if (!payload) {return false}
|
||||
const { comment_id } = payload
|
||||
|
||||
let formdata = new FormData();
|
||||
formdata.append("type", "delete");
|
||||
formdata.append("comment_id", comment_id);
|
||||
|
||||
API_Call((err,res)=> {
|
||||
ycore.API_Call((err,res)=> {
|
||||
return callback(err,res)
|
||||
},
|
||||
ycore.endpoints.comments_actions,
|
||||
formdata,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
function API_Call(callback, endpoint, payload, options){
|
||||
if (!payload || !endpoint) {
|
||||
return false
|
||||
}
|
||||
let payloadContainer = payload;
|
||||
payloadContainer.append("server_key", ycore.yConfig.server_key);
|
||||
const defaultOptions = { method: "POST", timeout: 0, processData: false }
|
||||
const { method, timeout, processData } = options || defaultOptions
|
||||
|
||||
const requestOptions = {
|
||||
"url": `${endpoint}${ycore.handlerYIDT.__token()}`,
|
||||
"method": method,
|
||||
"timeout": timeout,
|
||||
"data": payloadContainer,
|
||||
"mimeType": "multipart/form-data",
|
||||
"processData": processData,
|
||||
"contentType": false
|
||||
};
|
||||
|
||||
jquery.ajax(requestOptions)
|
||||
.done(response => {
|
||||
ycore.yconsole.log(response)
|
||||
return callback(false, response)
|
||||
})
|
||||
.fail(error => {
|
||||
ycore.yconsole.log('error', error)
|
||||
ycore.Alive_API.fail(error)
|
||||
return callback(true, error)
|
||||
});
|
||||
}
|
||||
export function GetGeneralData(callback){
|
||||
let formdata = new FormData();
|
||||
formdata.append("user_id", id);
|
||||
formdata.append("server_key", ycore.yConfig.server_key);
|
||||
const requestOptions = {
|
||||
method: 'POST',
|
||||
body: formdata,
|
||||
redirect: 'follow'
|
||||
};
|
||||
const urlObj = `${ycore.endpoints.get_general_data}${ycore.handlerYIDT.__token()}`
|
||||
fetch(urlObj, requestOptions)
|
||||
.then(response => {
|
||||
ycore.yconsole.log(response)
|
||||
return callback(false, response)
|
||||
})
|
||||
.catch(error => {
|
||||
console.log('error', error)
|
||||
ycore.Alive_API.fail(error)
|
||||
return callback(true, error)
|
||||
});
|
||||
}
|
||||
|
||||
export function follow_user(id, callback) {
|
||||
let formdata = new FormData();
|
||||
formdata.append("user_id", id);
|
||||
formdata.append("server_key", ycore.yConfig.server_key);
|
||||
const requestOptions = {
|
||||
method: 'POST',
|
||||
body: formdata,
|
||||
redirect: 'follow'
|
||||
};
|
||||
ycore.yconsole.log(`Following user => ${id} `)
|
||||
const urlObj = `${ycore.endpoints.follow_user}${ycore.handlerYIDT.__token()}`
|
||||
fetch(urlObj, requestOptions)
|
||||
.then(response => {
|
||||
ycore.yconsole.log(response)
|
||||
return callback(false, response)
|
||||
})
|
||||
.catch(error => {
|
||||
ycore.Alive_API.fail(error)
|
||||
console.log('error', error)
|
||||
return callback(true, error)
|
||||
});
|
||||
}
|
||||
|
||||
export const GetPostPrivacy = {
|
||||
bool: (e) => {
|
||||
switch (e) {
|
||||
case 'any':
|
||||
return '0'
|
||||
case 'only_followers':
|
||||
return '1'
|
||||
case 'only_follow':
|
||||
return '2'
|
||||
case 'private':
|
||||
return '3'
|
||||
default:
|
||||
return '0'
|
||||
},
|
||||
new: (callback, payload) => {
|
||||
if (!payload) {
|
||||
return false
|
||||
}
|
||||
},
|
||||
decorator: (e) => {
|
||||
switch (e) {
|
||||
case 'any':
|
||||
return <span><Icons.GlobalOutlined /> Share with everyone</span>
|
||||
case 'only_follow':
|
||||
return <span><Icons.TeamOutlined /> Share with people I follow</span>
|
||||
case 'only_followers':
|
||||
return <span><Icons.UsergroupAddOutlined /> Share with people follow me</span>
|
||||
case 'private':
|
||||
return <span><Icons.EyeInvisibleOutlined /> Dont share, only me</span>
|
||||
default:
|
||||
return <span>Unknown</span>
|
||||
}
|
||||
},
|
||||
|
||||
}
|
||||
|
||||
export function PublishPost(privacy, raw, file, callback){
|
||||
const rawtext = raw;
|
||||
if(!rawtext){
|
||||
return null
|
||||
}
|
||||
|
||||
let formdata = new FormData();
|
||||
formdata.append("user_id", ycore.handlerYIDT.__id());
|
||||
formdata.append("type", "new_post")
|
||||
formdata.append("server_key", ycore.yConfig.server_key);
|
||||
formdata.append("postPrivacy", privacy)
|
||||
formdata.append("postText", raw);
|
||||
file? formdata.append("postPhoto", file) : null
|
||||
|
||||
const requestOptions = {
|
||||
"url": `${ycore.endpoints.new_post}${ycore.handlerYIDT.__token()}`,
|
||||
"method": "POST",
|
||||
"timeout": 0,
|
||||
"data": formdata,
|
||||
"mimeType": "multipart/form-data",
|
||||
"processData": false,
|
||||
"contentType": false
|
||||
};
|
||||
const { post_id, raw_text } = payload
|
||||
|
||||
let formdata = new FormData();
|
||||
formdata.append("action", "comment");
|
||||
formdata.append("post_id", post_id);
|
||||
formdata.append("text", raw_text)
|
||||
|
||||
ycore.yconsole.log(`Sending new post => ${rawtext} `)
|
||||
jquery.ajax(requestOptions)
|
||||
.done(response => {
|
||||
ycore.yconsole.log(response)
|
||||
return callback(false, response)
|
||||
})
|
||||
.fail(error => {
|
||||
ycore.yconsole.log('error', error)
|
||||
ycore.Alive_API.fail(error)
|
||||
return callback(true, error)
|
||||
});
|
||||
ycore.API_Call((err,res)=> {
|
||||
return callback(err,res)
|
||||
},
|
||||
ycore.endpoints.action_post,
|
||||
formdata,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
export function FindUser(key, callback){
|
||||
export const comty_user = {
|
||||
setData: () => {
|
||||
|
||||
},
|
||||
follow: (callback, payload) => {
|
||||
if (!payload) {return false}
|
||||
const { user_id } = payload
|
||||
|
||||
let formdata = new FormData();
|
||||
formdata.append("server_key", ycore.yConfig.server_key);
|
||||
formdata.append("search_key", key);
|
||||
const urlOBJ = `${ycore.endpoints.find_user}${ycore.handlerYIDT.__token()}`
|
||||
const settings = {
|
||||
"url": urlOBJ,
|
||||
"method": "POST",
|
||||
"timeout": 10000,
|
||||
"processData": false,
|
||||
"mimeType": "multipart/form-data",
|
||||
"contentType": false,
|
||||
"data": formdata
|
||||
};
|
||||
jquery.ajax(settings)
|
||||
.done(function (response) {
|
||||
return callback(null, response);
|
||||
})
|
||||
.fail(function (response) {
|
||||
const exception = 'API Bad response';
|
||||
ycore.Alive_API.fail(response)
|
||||
return callback(exception, response);
|
||||
})
|
||||
}
|
||||
formdata.append("user_id", user_id);
|
||||
|
||||
ycore.API_Call((err,res)=> {
|
||||
return callback(err,res)
|
||||
},
|
||||
ycore.endpoints.follow_user,
|
||||
formdata,
|
||||
)
|
||||
},
|
||||
block:(callback, payload) => {
|
||||
// TO DO
|
||||
return false
|
||||
},
|
||||
find: (callback, payload) => {
|
||||
if (!payload) {return false}
|
||||
const { key } = payload
|
||||
|
||||
export function SeachKeywords(key, callback){
|
||||
let formdata = new FormData();
|
||||
formdata.append("server_key", ycore.yConfig.server_key);
|
||||
formdata.append("search_key", key);
|
||||
const urlOBJ = `${ycore.endpoints.search_endpoint}${ycore.handlerYIDT.__token()}`
|
||||
const settings = {
|
||||
"url": urlOBJ,
|
||||
"method": "POST",
|
||||
"timeout": 10000,
|
||||
"processData": false,
|
||||
"mimeType": "multipart/form-data",
|
||||
"contentType": false,
|
||||
"data": formdata
|
||||
};
|
||||
jquery.ajax(settings)
|
||||
.done(function (response) {
|
||||
return callback(null, response);
|
||||
})
|
||||
.fail(function (response) {
|
||||
const exception = 'Request Failed';
|
||||
ycore.Alive_API.fail(response)
|
||||
return callback(exception, response);
|
||||
})
|
||||
}
|
||||
export function ActionPost(type, id, value, callback){
|
||||
if (!type || !id) {
|
||||
ycore.notifyError('[ActionPost] No type or id Provided !!!')
|
||||
return false
|
||||
}
|
||||
var formdata = new FormData();
|
||||
formdata.append("server_key", ycore.yConfig.server_key);
|
||||
formdata.append("post_id", id);
|
||||
switch (type) {
|
||||
case 'like':
|
||||
{
|
||||
formdata.append("action", "like");
|
||||
break
|
||||
}
|
||||
case 'comment':
|
||||
{
|
||||
if (!value) {
|
||||
return false
|
||||
}
|
||||
formdata.append("action", "comment");
|
||||
formdata.append("text", value)
|
||||
break
|
||||
}
|
||||
case 'edit':
|
||||
{
|
||||
if (!value) {
|
||||
return false
|
||||
}
|
||||
formdata.append("action", "edit");
|
||||
formdata.append("text", value)
|
||||
break
|
||||
}
|
||||
case 'delete':
|
||||
{
|
||||
formdata.append("action", "delete");
|
||||
break
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
const urlOBJ = `${ycore.endpoints.action_post}${ycore.handlerYIDT.__token()}`
|
||||
const settings = {
|
||||
"url": urlOBJ,
|
||||
"method": "POST",
|
||||
"timeout": 3000,
|
||||
"processData": false,
|
||||
"mimeType": "multipart/form-data",
|
||||
"contentType": false,
|
||||
"data": formdata
|
||||
};
|
||||
jquery.ajax(settings)
|
||||
.done(function (response) {
|
||||
return callback(null, response);
|
||||
})
|
||||
.fail(function (response) {
|
||||
ycore.Alive_API.fail(response)
|
||||
return callback(true, `[Server error] We couldnt ${type} this post`);
|
||||
})
|
||||
}
|
||||
export function GetUserTags(id, callback){
|
||||
if (!id) {
|
||||
return false
|
||||
}
|
||||
let formdata = new FormData();
|
||||
formdata.append("server_key", ycore.yConfig.server_key);
|
||||
formdata.append("user_id", id )
|
||||
|
||||
const callOptions = { timeout: 10000 }
|
||||
ycore.API_Call((err,res)=> {
|
||||
return callback(err,res)
|
||||
},
|
||||
ycore.endpoints.find_user,
|
||||
formdata,
|
||||
callOptions
|
||||
)
|
||||
},
|
||||
__tags: (callback, payload) => {
|
||||
if (!payload) {return false}
|
||||
const { id } = payload
|
||||
|
||||
const urlOBJ = `${ycore.endpoints.get_user_tags}${ycore.handlerYIDT.__token()}`
|
||||
const settings = {
|
||||
"url": urlOBJ,
|
||||
"method": "POST",
|
||||
"timeout": 0,
|
||||
"processData": false,
|
||||
"mimeType": "multipart/form-data",
|
||||
"contentType": false,
|
||||
"data": formdata
|
||||
};
|
||||
jquery.ajax(settings)
|
||||
.done(function (response) {
|
||||
return callback(null, response);
|
||||
})
|
||||
.fail(function (response) {
|
||||
const exception = 'Request Failed';
|
||||
ycore.Alive_API.fail(response)
|
||||
return callback(exception, response);
|
||||
})
|
||||
}
|
||||
export function GetPosts(userid, type, fkey, callback) {
|
||||
let formdata = new FormData();
|
||||
formdata.append("server_key", ycore.yConfig.server_key);
|
||||
formdata.append("after_post_id", (fkey || 0))
|
||||
formdata.append("limit", ycore.AppSettings.limit_post_catch || 20)
|
||||
switch (type) {
|
||||
case 'feed':
|
||||
formdata.append("type", "get_news_feed");
|
||||
break;
|
||||
case 'user':
|
||||
formdata.append("type", "get_user_posts");
|
||||
formdata.append("id", userid)
|
||||
break;
|
||||
default:
|
||||
formdata.append("type", "get_news_feed");
|
||||
break;
|
||||
let formdata = new FormData();
|
||||
formdata.append("user_id", id )
|
||||
|
||||
ycore.API_Call((err,res)=> {
|
||||
return callback(err,res)
|
||||
},
|
||||
ycore.endpoints.get_user_tags,
|
||||
formdata
|
||||
)
|
||||
}
|
||||
const urlOBJ = `${ycore.endpoints.get_posts}${ycore.handlerYIDT.__token()}`
|
||||
const settings = {
|
||||
"url": urlOBJ,
|
||||
"method": "POST",
|
||||
"timeout": 10000,
|
||||
"processData": false,
|
||||
"mimeType": "multipart/form-data",
|
||||
"contentType": false,
|
||||
"data": formdata
|
||||
};
|
||||
jquery.ajax(settings)
|
||||
.done(function (response) {
|
||||
return callback(null, response);
|
||||
})
|
||||
.fail(function (response) {
|
||||
const exception = 'Request Failed';
|
||||
ycore.Alive_API.fail(response)
|
||||
return callback(exception, response);
|
||||
})
|
||||
}
|
||||
export function GetPostData(a, b, callback){
|
||||
if(!a){
|
||||
ycore.notifyError('Is required to provide an post id!!!')
|
||||
return false
|
||||
|
||||
export const comty_post = {
|
||||
getFeed: (callback, payload) => {
|
||||
if (!payload) {return false}
|
||||
const { fkey, type, id } = payload
|
||||
|
||||
let formdata = new FormData();
|
||||
formdata.append("after_post_id", (fkey || 0))
|
||||
formdata.append("limit", ycore.AppSettings.limit_post_catch || 20)
|
||||
switch (type) {
|
||||
case 'feed':
|
||||
formdata.append("type", "get_news_feed");
|
||||
break;
|
||||
case 'user':
|
||||
formdata.append("type", "get_user_posts");
|
||||
formdata.append("id", id)
|
||||
break;
|
||||
default:
|
||||
formdata.append("type", "get_news_feed");
|
||||
break;
|
||||
}
|
||||
ycore.API_Call((err,res)=> {
|
||||
return callback(err,res)
|
||||
},
|
||||
ycore.endpoints.get_posts,
|
||||
formdata,
|
||||
)
|
||||
|
||||
},
|
||||
get: (callback, payload) => {
|
||||
if (!payload) {return false}
|
||||
const { post_id, fetch } = payload
|
||||
|
||||
let formdata = new FormData();
|
||||
formdata.append("post_id", post_id)
|
||||
formdata.append("fetch", (fetch || "post_data,post_comments,post_wondered_users,post_liked_users"))
|
||||
|
||||
ycore.API_Call((err,res)=> {
|
||||
return callback(err,res)
|
||||
},
|
||||
ycore.endpoints.get_post_data,
|
||||
formdata
|
||||
)
|
||||
|
||||
},
|
||||
new: (callback, payload) => {
|
||||
if (!payload) {return false}
|
||||
const { privacy, text, file } = payload
|
||||
|
||||
let formdata = new FormData();
|
||||
formdata.append("type", "new_post")
|
||||
formdata.append("postPrivacy", privacy)
|
||||
formdata.append("postText", text);
|
||||
file? formdata.append("postPhoto", file) : null
|
||||
|
||||
const callOptions = { includeUserID: true }
|
||||
ycore.API_Call((err,res)=> {
|
||||
return callback(err,res)
|
||||
},
|
||||
ycore.endpoints.new_post,
|
||||
formdata,
|
||||
callOptions
|
||||
)
|
||||
},
|
||||
delete: (callback, payload) => {
|
||||
if (!payload) {return false}
|
||||
const { post_id } = payload
|
||||
|
||||
let formdata = new FormData();
|
||||
formdata.append("action", "delete");
|
||||
formdata.append("post_id", post_id)
|
||||
|
||||
ycore.API_Call((err,res)=> {
|
||||
return callback(err,res)
|
||||
},
|
||||
ycore.endpoints.action_post,
|
||||
formdata,
|
||||
)
|
||||
},
|
||||
save: (callback, payload) => {
|
||||
|
||||
},
|
||||
edit: (callback, payload) =>{
|
||||
|
||||
},
|
||||
__pin: (callback, payload) => {
|
||||
|
||||
},
|
||||
__boost: (callback, payload) => {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
export const comty_search = {
|
||||
keywords: (callback, payload) =>{
|
||||
if (!payload) {return false}
|
||||
const { key } = payload
|
||||
|
||||
let formdata = new FormData();
|
||||
formdata.append("search_key", key);
|
||||
|
||||
const callOptions = { timeout: 10000 }
|
||||
ycore.API_Call((err,res)=> {
|
||||
return callback(err,res)
|
||||
},
|
||||
ycore.endpoints.search_endpoint,
|
||||
formdata,
|
||||
callOptions
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
export const comty_get = {
|
||||
session_data: () => {
|
||||
|
||||
},
|
||||
general_data: () => {
|
||||
if (!payload) {return false}
|
||||
const { id } = payload
|
||||
|
||||
let formdata = new FormData();
|
||||
formdata.append("user_id", id);
|
||||
|
||||
ycore.API_Call((err,res)=> {
|
||||
return callback(err,res)
|
||||
},
|
||||
ycore.endpoints.get_general_data,
|
||||
formdata
|
||||
)
|
||||
}
|
||||
let formdata = new FormData();
|
||||
formdata.append("server_key", ycore.yConfig.server_key);
|
||||
formdata.append("post_id", a)
|
||||
formdata.append("fetch", (b || "post_data,post_comments,post_wondered_users,post_liked_users"))
|
||||
|
||||
const urlOBJ = `${ycore.endpoints.get_post_data}${ycore.handlerYIDT.__token()}`
|
||||
const settings = {
|
||||
"url": urlOBJ,
|
||||
"method": "POST",
|
||||
"timeout": 10000,
|
||||
"processData": false,
|
||||
"mimeType": "multipart/form-data",
|
||||
"contentType": false,
|
||||
"data": formdata
|
||||
};
|
||||
jquery.ajax(settings)
|
||||
.done(function (response) {
|
||||
return callback(null, response);
|
||||
})
|
||||
.fail(function (response) {
|
||||
const exception = 'Request Failed';
|
||||
ycore.Alive_API.fail(response)
|
||||
return callback(exception, response);
|
||||
})
|
||||
}
|
||||
|
||||
export const get_app_session = {
|
||||
@ -447,3 +298,36 @@ export const get_app_session = {
|
||||
.catch(error => ycore.yconsole.log('error', error));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export const GetPostPrivacy = {
|
||||
bool: (e) => {
|
||||
switch (e) {
|
||||
case 'any':
|
||||
return '0'
|
||||
case 'only_followers':
|
||||
return '1'
|
||||
case 'only_follow':
|
||||
return '2'
|
||||
case 'private':
|
||||
return '3'
|
||||
default:
|
||||
return '0'
|
||||
}
|
||||
},
|
||||
decorator: (e) => {
|
||||
switch (e) {
|
||||
case 'any':
|
||||
return <span><Icons.GlobalOutlined /> Share with everyone</span>
|
||||
case 'only_follow':
|
||||
return <span><Icons.TeamOutlined /> Share with people I follow</span>
|
||||
case 'only_followers':
|
||||
return <span><Icons.UsergroupAddOutlined /> Share with people follow me</span>
|
||||
case 'private':
|
||||
return <span><Icons.EyeInvisibleOutlined /> Dont share, only me</span>
|
||||
default:
|
||||
return <span>Unknown</span>
|
||||
}
|
||||
},
|
||||
|
||||
}
|
62
src/@ycore/libs/rs_cloud/pre.js
Normal file
62
src/@ycore/libs/rs_cloud/pre.js
Normal file
@ -0,0 +1,62 @@
|
||||
import jquery from 'jquery'
|
||||
import * as ycore from 'ycore'
|
||||
import { FormatColorResetOutlined } from '@material-ui/icons'
|
||||
|
||||
export const Alive_API = {
|
||||
fail: (a) => {
|
||||
if (a){
|
||||
ycore.yconsole.log(a)
|
||||
ycore.notify.error(a)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function API_Call(callback, endpoint, payload, options){
|
||||
if (!payload || !endpoint) {
|
||||
return false
|
||||
}
|
||||
let payloadContainer = payload;
|
||||
payloadContainer.append("server_key", ycore.yConfig.server_key);
|
||||
|
||||
let method;
|
||||
let timeout;
|
||||
let processData;
|
||||
let includeUserID;
|
||||
|
||||
if (options) {
|
||||
method = options.method? options.method : "POST"
|
||||
timeout = options.timeout? options.timeout : 0
|
||||
processData = options.processData? options.processData : false
|
||||
includeUserID = options.includeUserID? options.includeUserID : false
|
||||
}else {
|
||||
method = "POST"
|
||||
timeout = 0
|
||||
processData = false
|
||||
includeUserID = false
|
||||
}
|
||||
|
||||
if (includeUserID) {
|
||||
payloadContainer.append("user_id", ycore.handlerYIDT.__id());
|
||||
}
|
||||
|
||||
const requestOptions = {
|
||||
"url": `${endpoint}${ycore.handlerYIDT.__token()}`,
|
||||
"method": method,
|
||||
"timeout": timeout,
|
||||
"data": payloadContainer,
|
||||
"mimeType": "multipart/form-data",
|
||||
"processData": processData,
|
||||
"contentType": false
|
||||
};
|
||||
|
||||
jquery.ajax(requestOptions)
|
||||
.done(response => {
|
||||
ycore.yconsole.log(response)
|
||||
return callback(false, response)
|
||||
})
|
||||
.fail(error => {
|
||||
ycore.yconsole.log('error', error)
|
||||
ycore.Alive_API.fail(error)
|
||||
return callback(true, error)
|
||||
});
|
||||
}
|
@ -11,14 +11,7 @@ var jwt = require("jsonwebtoken")
|
||||
export function userData(){
|
||||
return ycore.handlerYIDT.get()
|
||||
}
|
||||
export const Alive_API = {
|
||||
fail: (a) => {
|
||||
if (a){
|
||||
ycore.yconsole.log(a)
|
||||
ycore.notify.error(a)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function __API__User (payload, sdcp, callback){
|
||||
const { UserID, UserToken } = payload
|
||||
|
@ -16,6 +16,7 @@ import React from "react";
|
||||
|
||||
import config from "config"
|
||||
import "./libs.js"
|
||||
import { func } from "prop-types";
|
||||
|
||||
export * from "../../config/app.settings.js"
|
||||
export * from "./libs.js"
|
||||
@ -66,6 +67,36 @@ export function b64toBlob(b64Data, contentType, sliceSize) {
|
||||
var blob = new Blob(byteArrays, {type: contentType});
|
||||
return blob;
|
||||
}
|
||||
|
||||
export function ReadFileAsB64(file, callback){
|
||||
if (file) {
|
||||
var reader = new FileReader();
|
||||
|
||||
reader.onload = function(readerEvt) {
|
||||
var binaryString = readerEvt.target.result;
|
||||
const a = `data:image/png;base64, ${btoa(binaryString)}`
|
||||
return callback(a)
|
||||
};
|
||||
|
||||
reader.readAsBinaryString(file);
|
||||
}
|
||||
}
|
||||
|
||||
export function uploadFile(file) {
|
||||
var formData = new FormData();
|
||||
formData.append("userfile", file);
|
||||
var request = new XMLHttpRequest();
|
||||
request.onload = function () {
|
||||
if (request.status == 200) {
|
||||
return true
|
||||
} else {
|
||||
alert('Error! Upload failed');
|
||||
}
|
||||
};
|
||||
request.open("POST", "/temp/file");
|
||||
request.send(formData);
|
||||
}
|
||||
|
||||
export const time = {
|
||||
ago: (a) => {
|
||||
const format = moment(a).format('DDMMYYYY');
|
||||
@ -295,4 +326,5 @@ export const yconsole = {
|
||||
SettingStoragedValue('force_showDevLogs')? console.warn(...cont) : null
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -65,6 +65,22 @@ export class __secComments extends React.Component {
|
||||
console.log(`Removing Comment with id => ${id}`)
|
||||
ycore.Post_Comments.delete((err, res) => { if(err){return false} return this.reloadComments() }, {comment_id: id})
|
||||
}
|
||||
handleNewComment(){
|
||||
const { raw_comment } = this.state
|
||||
const { post_id } = this.props
|
||||
if (raw_comment) {
|
||||
const payload = { post_id: post_id, raw_text: raw_comment }
|
||||
ycore.Post_Comments.new((err,res) =>{
|
||||
if (err) {
|
||||
ycore.notify.error('This action could not be performed.', err)
|
||||
}
|
||||
this.setState({ raw_comment: '' })
|
||||
return this.reloadComments()
|
||||
}, payload)
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
renderComment = (a) => {
|
||||
const {id, time, Orginaltext, publisher} = a
|
||||
const CommentMenu = (
|
||||
@ -95,29 +111,17 @@ export class __secComments extends React.Component {
|
||||
reloadComments(){
|
||||
try {
|
||||
this.setState({ loading: true })
|
||||
ycore.GetPostData(this.props.post_id, null, (err, res) =>{
|
||||
const payload = { post_id: this.props.post_id }
|
||||
ycore.comty_post.get((err, res) => {
|
||||
const post_comments = JSON.parse(res)['post_comments']
|
||||
this.setState({ comment_data: post_comments, loading: false})
|
||||
})
|
||||
}, payload)
|
||||
|
||||
} catch (error) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
dispatchNewComment(){
|
||||
const { raw_comment } = this.state
|
||||
const { post_id } = this.props
|
||||
if (raw_comment) {
|
||||
ycore.ActionPost('comment', post_id, raw_comment, (err,res) =>{
|
||||
if (err) {
|
||||
ycore.notify.error('This action could not be performed.', err)
|
||||
}
|
||||
this.setState({ raw_comment: '' })
|
||||
this.reloadComments()
|
||||
return true
|
||||
})
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
|
||||
render(){
|
||||
@ -141,7 +145,7 @@ export class __secComments extends React.Component {
|
||||
</div>
|
||||
<div className={styles.comment_box}>
|
||||
<div className={styles.comment_box_body}>
|
||||
<antd.Input value={this.state.raw_comment} onPressEnter={() => this.dispatchNewComment()} placeholder="Write a comment..." allowClear onChange={this.HandleCommentInput} />
|
||||
<antd.Input value={this.state.raw_comment} onPressEnter={() => this.handleNewComment()} placeholder="Write a comment..." allowClear onChange={this.HandleCommentInput} />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
@ -63,20 +63,22 @@ class MainFeed extends React.Component {
|
||||
return
|
||||
}
|
||||
this.toogleLoader()
|
||||
ycore.GetPosts(uid, get, '0', (err, result) => {
|
||||
if (err) {
|
||||
ycore.notifyError('Error when get data from this input')
|
||||
return
|
||||
}
|
||||
if (JSON.parse(result).api_status == '400') {
|
||||
this.setState({ invalid: true })
|
||||
const payload = { fkey: 0, type: get, id: uid }
|
||||
ycore.comty_post.getFeed((err,res) => {
|
||||
if (err) {
|
||||
ycore.notifyError('Error when get data from this input')
|
||||
return
|
||||
}
|
||||
const parsed = JSON.parse(result)['data']
|
||||
|
||||
const isEnd = parsed.length < ycore.AppSettings.limit_post_catch? true : false
|
||||
this.setState({ isEnd: isEnd, data: parsed, loading: false })
|
||||
})
|
||||
if (JSON.parse(res).api_status == '400') {
|
||||
this.setState({ invalid: true })
|
||||
return
|
||||
}
|
||||
const parsed = JSON.parse(res)['data']
|
||||
|
||||
const isEnd = parsed.length < ycore.AppSettings.limit_post_catch? true : false
|
||||
this.setState({ isEnd: isEnd, data: parsed, loading: false })
|
||||
}, payload)
|
||||
|
||||
}catch(err){
|
||||
ycore.notifyError('err')
|
||||
}
|
||||
@ -96,15 +98,16 @@ class MainFeed extends React.Component {
|
||||
const getLastPost = ycore.objectLast(this.state.data)
|
||||
ycore.yconsole.log('LAST POST ID =>', getLastPost.id)
|
||||
|
||||
ycore.GetPosts(uid, get, getLastPost.id, (err, res) => {
|
||||
if (err){return false}
|
||||
const oldData = this.state.data
|
||||
const parsed = JSON.parse(res)['data']
|
||||
const mix = oldData.concat(parsed)
|
||||
const isEnd = parsed.length < ycore.AppSettings.limit_post_catch? true : false
|
||||
this.setState({ isEnd: isEnd, data: mix, loading: false }, () => ycore.gotoElement(getLastPost.id) )
|
||||
return true
|
||||
})
|
||||
const payload = { fkey: getLastPost.id, type: get, id: uid }
|
||||
ycore.comty_post.getFeed((err,res) => {
|
||||
if (err){return false}
|
||||
const oldData = this.state.data
|
||||
const parsed = JSON.parse(res)['data']
|
||||
const mix = oldData.concat(parsed)
|
||||
const isEnd = parsed.length < ycore.AppSettings.limit_post_catch? true : false
|
||||
this.setState({ isEnd: isEnd, data: mix, loading: false }, () => ycore.gotoElement(getLastPost.id) )
|
||||
return true
|
||||
}, payload)
|
||||
}catch(err){
|
||||
ycore.notifyError(err)
|
||||
}
|
||||
|
@ -61,11 +61,11 @@ class PostCard extends React.PureComponent{
|
||||
|
||||
goToPost(postID){
|
||||
localStorage.setItem('p_back_uid', postID)
|
||||
ycore.GetPostData(postID, null, (err, res) => {
|
||||
console.log(res)
|
||||
const payload = {post_id: postID}
|
||||
ycore.comty_post.get((err,res)=>{
|
||||
if (err) { return false }
|
||||
ycore.SecondarySwap.openPost(res)
|
||||
})
|
||||
}, payload)
|
||||
}
|
||||
|
||||
render(){
|
||||
@ -74,13 +74,13 @@ class PostCard extends React.PureComponent{
|
||||
const { id, post_time, postText, postFile, publisher, post_likes, is_post_pinned, is_liked, post_comments } = payload || emptyPayload;
|
||||
const handlePostActions = {
|
||||
delete: (post_id) => {
|
||||
ycore.ActionPost('delete', post_id, null, (err, res)=>{
|
||||
const payload = {post_id: post_id}
|
||||
ycore.comty_post.delete((err,res)=> {
|
||||
if (err) {
|
||||
return false
|
||||
}
|
||||
ycore.yconsole.log(res)
|
||||
ycore.FeedHandler.killByID(post_id)
|
||||
})
|
||||
}, payload)
|
||||
},
|
||||
save: () => {
|
||||
|
||||
|
@ -4,6 +4,7 @@ import * as ycore from 'ycore'
|
||||
import styles from './index.less'
|
||||
import * as Icons from '@ant-design/icons';
|
||||
import Icon from '@ant-design/icons'
|
||||
import $ from 'jquery'
|
||||
import * as MICONS from '@material-ui/icons'
|
||||
|
||||
import Post_options from './local_components/post_options'
|
||||
@ -20,6 +21,7 @@ export function HandleVisibility(){
|
||||
window.PostCreatorComponent.ToogleVisibility();
|
||||
return
|
||||
}
|
||||
|
||||
class PostCreator extends React.PureComponent{
|
||||
constructor(props){
|
||||
super(props),
|
||||
@ -74,7 +76,6 @@ class PostCreator extends React.PureComponent{
|
||||
ToogleVisibility(){
|
||||
this.setState({ visible: !this.state.visible })
|
||||
}
|
||||
|
||||
ToogleUpload(){
|
||||
this.setState({ uploader: !this.state.uploader })
|
||||
}
|
||||
@ -87,13 +88,10 @@ class PostCreator extends React.PureComponent{
|
||||
return;
|
||||
}
|
||||
if (info.file.status === 'done') {
|
||||
this.setState({ file: info.file.originFileObj, uploader: false })
|
||||
getBase64(info.file.originFileObj, fileURL =>
|
||||
this.setState({
|
||||
fileURL,
|
||||
loading: false,
|
||||
}),
|
||||
);
|
||||
this.setState({ file: info.file.originFileObj, uploader: false })
|
||||
getBase64(info.file.originFileObj, fileURL =>{
|
||||
this.setState({fileURL,loading: false})
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@ -143,14 +141,17 @@ class PostCreator extends React.PureComponent{
|
||||
return null
|
||||
}
|
||||
this.setState({ posting: true, keys_remaining: ycore.AppSettings.MaxLengthPosts })
|
||||
ycore.PublishPost(ycore.GetPostPrivacy.bool(shareWith), rawtext, file, (err, res) => {
|
||||
if (err) {
|
||||
ycore.notifyError(err)
|
||||
return
|
||||
}
|
||||
this.FlushPostState()
|
||||
|
||||
})
|
||||
|
||||
|
||||
const payload = { privacy: ycore.GetPostPrivacy.bool(shareWith), text: rawtext, file: file }
|
||||
ycore.comty_post.new((err,res)=>{
|
||||
if (err) {
|
||||
ycore.notify.error(err)
|
||||
return false
|
||||
}
|
||||
this.FlushPostState()
|
||||
},payload)
|
||||
|
||||
}
|
||||
dropRef = React.createRef()
|
||||
|
||||
@ -172,6 +173,27 @@ class PostCreator extends React.PureComponent{
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
const _this = this
|
||||
$("body").bind('paste', function(je){
|
||||
var e = je.originalEvent;
|
||||
for (var i = 0; i < e.clipboardData.items.length; i++) {
|
||||
var item = e.clipboardData.items[i];
|
||||
ycore.yconsole.log('Item: ' + item.type);
|
||||
if (item.type.indexOf('image') != -1) {
|
||||
//item.
|
||||
let a = item.getAsFile()
|
||||
a
|
||||
_this.setState({ file: a })
|
||||
ycore.ReadFileAsB64(a, (res) =>{
|
||||
_this.setState({ fileURL: res })
|
||||
})
|
||||
} else {
|
||||
// ignore not images
|
||||
ycore.yconsole.log('Discarding not image paste data');
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
let div = this.dropRef.current
|
||||
div.addEventListener('dragenter', this.handleDragIn)
|
||||
div.addEventListener('dragleave', this.handleDragOut)
|
||||
@ -207,7 +229,7 @@ class PostCreator extends React.PureComponent{
|
||||
<antd.Menu.Item key="private">{ycore.GetPostPrivacy.decorator("private")}</antd.Menu.Item>
|
||||
</antd.Menu>
|
||||
)
|
||||
|
||||
|
||||
if (visible) {
|
||||
return(
|
||||
<div className={styles.cardWrapper}>
|
||||
|
@ -23,11 +23,12 @@ class UserProfile extends React.Component {
|
||||
}
|
||||
|
||||
handleFollowUser = () => {
|
||||
ycore.follow_user(this.state.UUID, (exception, response)=>{
|
||||
if(exception){return ycore.notifyError(exception) }
|
||||
const payload = { user_id: this.state.UUID }
|
||||
ycore.comty_user.follow((err,res)=> {
|
||||
if (err) { return false }
|
||||
this.setState({Followed: !this.state.Followed})
|
||||
return
|
||||
})
|
||||
}, payload)
|
||||
}
|
||||
|
||||
componentDidMount(){
|
||||
@ -40,11 +41,12 @@ class UserProfile extends React.Component {
|
||||
const parsed = e.shift()
|
||||
const raw = parsed.toString()
|
||||
const string = raw.replace('/@', "")
|
||||
|
||||
ycore.FindUser(string, (exception, response)=> {
|
||||
exception? ycore.notifyError(exception) : null
|
||||
|
||||
const payload = { key: string }
|
||||
ycore.comty_user.find((err,res)=>{
|
||||
err? ycore.notifyError(err) : null
|
||||
try {
|
||||
const rp = JSON.parse(response)
|
||||
const rp = JSON.parse(res)
|
||||
ycore.yconsole.log(rp)
|
||||
if (!rp['0']) {
|
||||
ycore.yconsole.log('Bad response / User not found')
|
||||
@ -60,17 +62,20 @@ class UserProfile extends React.Component {
|
||||
ycore.yconsole.log(`Using aproximate user! => ${c1} / ${c2}`)
|
||||
ycore.crouter.native(`@${c1}`)
|
||||
}
|
||||
ycore.GetUserTags(rp['0'].user_id, (err, res) => {
|
||||
|
||||
const payload = { id: rp['0'].user_id }
|
||||
ycore.comty_user.__tags((err,res)=>{
|
||||
if (err) {
|
||||
ycore.notifyError(err)
|
||||
return
|
||||
}
|
||||
})
|
||||
},payload)
|
||||
|
||||
this.setState({ UUID: rp['0'].user_id, RenderValue: rp['0'], loading: false , Followed: ycore.booleanFix(rp['0'].is_following)})
|
||||
} catch (err) {
|
||||
ycore.notifyError(err)
|
||||
}
|
||||
})
|
||||
},payload)
|
||||
|
||||
}
|
||||
|
||||
|
@ -16,10 +16,12 @@ export default class Indexer_Post extends React.Component{
|
||||
}
|
||||
|
||||
toSwap(id){
|
||||
ycore.GetPostData(id, null, (err, res) => {
|
||||
const payload = {post_id: id}
|
||||
ycore.comty_post.get((err,res)=>{
|
||||
if (err) { return false }
|
||||
ycore.SecondarySwap.openPost(res)
|
||||
})
|
||||
}, payload)
|
||||
|
||||
}
|
||||
|
||||
componentDidMount(){
|
||||
|
@ -25,13 +25,17 @@ class SearchPageIndexer extends PureComponent {
|
||||
const parsed = matchSearch.shift()
|
||||
const raw = parsed.toString()
|
||||
const string = raw.replace('/s/', "")
|
||||
ycore.SeachKeywords(string, (exception, response) => {
|
||||
ycore.yconsole.log('Founded entries => ', JSON.parse(response))
|
||||
exception? ycore.notifyError(exception) : null
|
||||
this.setState({ SearchResult: response })
|
||||
|
||||
const payload = {key: string}
|
||||
ycore.comty_search.keywords((err,res) =>{
|
||||
if (err) {
|
||||
ycore.notifyError(err)
|
||||
}
|
||||
ycore.yconsole.log('Founded entries => ', JSON.parse(res))
|
||||
this.setState({ SearchResult: res })
|
||||
this.toogleLoading()
|
||||
})
|
||||
|
||||
}, payload)
|
||||
|
||||
} catch (err) {
|
||||
ycore.notifyError(err)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user