updated to the new Pikotools api (new Space struct)

This commit is contained in:
2021-04-09 17:50:58 +02:00
parent 00b980e74b
commit 35e10ed469
52 changed files with 795 additions and 736 deletions

View File

@@ -59,8 +59,6 @@ Upload::Upload()
void Upload::Init()
{
json_serializer.TreatAsTable(L"files");
json_serializer.TreatAsNumeric(L"size");
}
@@ -146,9 +144,10 @@ void Upload::CreateThumb(Item & item)
void Upload::UploadFile(Item & item, const std::wstring & tmp_filename)
{
// we should add the file beforehand to get the proper item.id
cur->request->status = system->AddFile(item, 0, false);
cur->request->status = WINIX_ERR_PERMISSION_DENIED;
bool status = system->AddFile(item, 0, false);
if( cur->request->status == WINIX_ERR_OK )
if( status )
{
if( system->CreateNewFile(item) )
{
@@ -160,6 +159,7 @@ void Upload::UploadFile(Item & item, const std::wstring & tmp_filename)
//cur->request->status = db->EditFileById(item, item.id);
if( item.update(item_model_data) )
{
cur->request->status = WINIX_ERR_OK;
plugin->Call(WINIX_FILE_ADDED, &item);
if( item.item_content.file_type == WINIX_ITEM_FILETYPE_IMAGE )
@@ -174,10 +174,6 @@ void Upload::UploadFile(Item & item, const std::wstring & tmp_filename)
if( is_jquery_upload )
cur->request->item_tab.push_back(item);
}
else
{
cur->request->status = WINIX_ERR_PERMISSION_DENIED;
}
}
else
{
@@ -246,6 +242,8 @@ void Upload::UploadMulti()
void Upload::UploadSingle()
{
cur->request->item.Clear(); // clearing and setting date
const std::wstring & new_subject = cur->request->PostVar(L"subject");
const std::wstring & new_url = cur->request->PostVar(L"url");
bool has_subject = !new_subject.empty();
@@ -308,29 +306,33 @@ void Upload::MakePost()
void Upload::CreateAnswer()
{
Request & req = *cur->request;
PT::Space & files = req.info.AddSpace(L"files"); // 'files' will be serialized to an array
PT::Space & files = req.info.add_empty_space(L"files");
for(size_t i=0 ; i<req.item_tab.size() ; ++i)
{
PT::Space & file = files.AddSpace(L"");
PT::Space & file = files.add_empty_space();
file.Add(L"name", req.item_tab[i].url);
file.Add(L"size", req.item_tab[i].item_content.file_size);
file.add(L"name", req.item_tab[i].url);
file.add(L"size", req.item_tab[i].item_content.file_size);
std::wstring & link = file.Add(L"url", L"");
std::wstring link;
system->CreateItemLink(req.item_tab[i], link);
file.add(L"url", link);
std::wstring & del_url = file.Add(L"deleteUrl", link);
del_url += L"/rm/jquery_upload";
std::wstring delete_url = link;
delete_url += L"/rm/jquery_upload";
file.add(L"deleteUrl", delete_url);
file.Add(L"deleteType", L"POST");
file.add(L"deleteType", L"POST");
if( req.item_tab[i].item_content.file_type == WINIX_ITEM_FILETYPE_IMAGE )
{
std::wstring & thumb = file.Add(L"thumbnailUrl", link);
std::wstring thumb = link;
if( req.item_tab[i].item_content.file_has_thumb )
thumb += L"/-/thumb";
file.add(L"thumbnailUrl", thumb);
}
/*
@@ -341,10 +343,6 @@ void Upload::CreateAnswer()
cur->request->return_json = true;
cur->request->return_info_only = true;
cur->request->info_serializer = &json_serializer;
//cur->request->out_headers.Add(L"Content-Type", L"text/html");
}