changed organization of static files

removed: item.auth item.auth_path
added:   item.file_path, item.file_fs, item.file_type
now the path to a static file is a relative path
added: thumbnails (not finished yet)
fixed: db didn't correctly return the number of deleted items /DelItem() method/




git-svn-id: svn://ttmath.org/publicrep/winix/trunk@696 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
2010-12-10 21:07:01 +00:00
parent 9b29cce1a4
commit 36c8822e6c
41 changed files with 435 additions and 364 deletions

View File

@@ -7,6 +7,7 @@
*
*/
#include "wand/MagickWand.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <cstdio>
@@ -14,6 +15,7 @@
#include "upload.h"
#include "core/misc.h"
#include "functions/functions.h"
#include "utf8.h"
@@ -38,21 +40,9 @@ bool Upload::HasAccess(const Item & item)
if( !system->mounts.pmount )
return false;
if( system->mounts.pmount->fs == system->mounts.MountFsSimplefs() && config->auth_simplefs_dir.empty() )
if( config->upload_dir.empty() )
{
log << log1 << "Request: can't use upload function, auth_simplefs_dir must be set in the config file" << logend;
return false;
}
if( system->mounts.pmount->fs == system->mounts.MountFsHashfs() && config->auth_hashfs_dir.empty() )
{
log << log1 << "Request: can't use upload function, auth_hashfs_dir must be set in the config file" << logend;
return false;
}
if( config->auth_tmp_dir.empty() )
{
log << log1 << "Request: can't use upload function, auth_tmp_dir must be set in the config file" << logend;
log << log1 << "Request: can't use upload function, upload_dir must be set in the config file" << logend;
return false;
}
@@ -77,40 +67,78 @@ return true;
bool Upload::UploadCreatePath()
void Upload::CreateThumbnail(const Item & item)
{
if( !system->MakePath(request->item, true) )
if( !system->MakeFilePath(item, path) ||
!system->MakeFilePath(item, path_thumb, true, true, config->upload_dirs_chmod) )
return;
Ezc::WideToUTF8(path, patha);
Ezc::WideToUTF8(path_thumb, path_thumba);
MagickWand * wand = NewMagickWand();
if( MagickReadImage(wand, patha.c_str()) )
{
//log <<log1 << "images: " << MagickGetNumberImages(wand) << logend << logsavenow;
//MagickResizeImage(wand, config->images_thumb_cx, config->images_thumb_cy, CubicFilter, 0.25);
//MagickScaleImage(wand, 100, 100);
MagickThumbnailImage(wand, config->thumb_cx, config->thumb_cy);
if( MagickWriteImage(wand, path_thumba.c_str()) )
log << log3 << "Upload: created a thumbnail: " << path_thumba << logend;
}
DestroyMagickWand(wand);
}
bool Upload::UploadSaveStaticFile(const Item & item, const std::wstring & tmp_filename)
{
if( !system->MakeFilePath(item, path, false, true, config->upload_dirs_chmod) )
{
request->status = WINIX_ERR_PERMISSION_DENIED;
return false;
}
return true;
}
void Upload::UploadSaveFile(const std::wstring & tmp_filename, const std::wstring & destination)
{
if( RenameFile(tmp_filename, destination) )
if( RenameFile(tmp_filename, path) )
{
log << log1 << "Content: uploaded a new file: " << destination << logend;
log << log1 << "Upload: uploaded a new file: " << path << logend;
return true;
}
else
{
int err = errno;
// !! skasowac takze plik z bazy danych?
log << log1 << "Content: can't move the tmp file from: " << tmp_filename << ", to: " << destination << ", ";
log.SystemErr(err);
log << logend;
log << log1 << "Upload: can't move the tmp file from: " << tmp_filename << ", to: " << path << logend;
request->status = WINIX_ERR_PERMISSION_DENIED;
return false;
}
}
void Upload::UploadFile(Item & item, const std::wstring & tmp_filename)
{
// we should add the file beforehand to get the proper item.id
request->status = system->AddFile(item);
if( request->status == WINIX_ERR_OK )
{
if( system->CreateNewFile(item) )
{
if( UploadSaveStaticFile(item, tmp_filename) )
{
request->status = db->EditFileById(item, item.id);
if( item.file_type == WINIX_ITEM_FILETYPE_IMAGE && config->create_thumb )
CreateThumbnail(item);
}
else
{
db->DelItem(item);
}
}
}
}
bool Upload::FunUploadCheckAbuse()
{
@@ -136,7 +164,6 @@ return true;
void Upload::UploadMulti()
{
request->item.Clear(); // clearing and setting date
@@ -151,21 +178,12 @@ void Upload::UploadMulti()
{
const wchar_t * file_name = i->second.filename.c_str();
request->item.subject = file_name;
request->item.url = file_name;
request->item.auth = SelectFileType(file_name);
request->item.subject = file_name;
request->item.url = file_name;
request->item.file_type = SelectFileType(file_name);
functions->PrepareUrl(request->item);
request->status = system->AddFile(request->item);
if( !UploadCreatePath() )
return;
if( request->status == WINIX_ERR_OK )
{
UploadSaveFile(i->second.tmp_filename, request->item.auth_path);
request->status = db->EditAuthById(request->item, request->item.id);
}
UploadFile(request->item, i->second.tmp_filename);
}
system->RedirectToLastDir();
@@ -177,14 +195,14 @@ void Upload::UploadSingle()
const std::wstring & new_subject = request->PostVar(L"subject");
const std::wstring & new_url = request->PostVar(L"url");
bool has_subject = !new_subject.empty();
bool has_url = !new_url.empty(); //(new_url && (*new_url)[0] != 0 );
bool has_url = !new_url.empty();
functions->ReadItem(request->item, Item::file); // ReadItem() changes the url if it is empty
functions->SetUser(request->item);
request->item.privileges = 0644; // !! tymczasowo
const wchar_t * file_name = request->post_file_tab.begin()->second.filename.c_str();
request->item.auth = SelectFileType(file_name);
request->item.file_type = SelectFileType(file_name);
if( !has_subject )
request->item.subject = file_name;
@@ -194,19 +212,8 @@ void Upload::UploadSingle()
request->item.url = file_name;
functions->PrepareUrl(request->item);
}
request->status = system->AddFile(request->item);
// url can be changed by PostFunEmacsAdd()
if( !UploadCreatePath() )
return;
if( request->status == WINIX_ERR_OK )
{
const std::wstring & tmp_filename = request->post_file_tab.begin()->second.tmp_filename;
UploadSaveFile(tmp_filename, request->item.auth_path);
request->status = db->EditAuthById(request->item, request->item.id);
}
UploadFile(request->item, request->post_file_tab.begin()->second.tmp_filename);
if( request->status == WINIX_ERR_OK )
system->RedirectTo(request->item, L"/cat");