Archived
242 lines
8.3 KiB
C++
242 lines
8.3 KiB
C++
#include <mysql.hpp>
|
|
#include <database.hpp>
|
|
#include <html5.hpp>
|
|
#include <string>
|
|
#include <cgicc/Cgicc.h>
|
|
#include <iostream>
|
|
|
|
bool login=false;
|
|
bool member=false;
|
|
|
|
int main(){
|
|
mysqlpp::Connection database;
|
|
userdata user;
|
|
cgicc::Cgicc cgi;
|
|
std::string s_id = get_cookie(cgi,"id");
|
|
std::string s_loginkey = get_cookie(cgi,"loginkey");
|
|
if(s_id==""||s_id.find_first_not_of("0123456789")!=std::string::npos||std::stoul(s_id)>UINT64_MAX){
|
|
s_id="";
|
|
}
|
|
if(s_loginkey==""||s_loginkey.find_first_not_of("0123456789")!=std::string::npos||std::stoul(s_loginkey)>UINT64_MAX){
|
|
s_loginkey="";
|
|
}
|
|
if(!connect_mysql(&database)){
|
|
std::cout << "Content-type:text/html\r\n\r\n"
|
|
<< "<html>\n"
|
|
<< "<head>\n"
|
|
<< "<meta charset=\"utf-8\">\n"
|
|
<< "<title>出现错误!</title>\n"
|
|
<< "</head>\n"
|
|
<< "<body>\n"
|
|
<< "数据库连接失败,请检查服务器状态!\n"
|
|
<< "</body>\n"
|
|
<< "</html>\n";
|
|
return 0;
|
|
}
|
|
if(s_id!=""&&query_userdata(database,&user,"id = "+s_id)){
|
|
if(s_loginkey!=""&&user.loginkey==std::stoul(s_loginkey)){
|
|
login=true;
|
|
}
|
|
if(user.status=='m'){
|
|
member=true;
|
|
}
|
|
if(!login&&member){
|
|
member=false;
|
|
}
|
|
}
|
|
if(!login){
|
|
std::cout << "Status: 302 Found\r\n"
|
|
<< "Location: /\r\n" << std::endl;
|
|
}else{
|
|
std::string vid = cgi.getElement("v")->getValue();
|
|
if(vid.find_first_not_of("0123456789")!=std::string::npos){
|
|
std::cout << "Status: 403 Forbidden\r\n" << std::endl;
|
|
return 0;
|
|
}
|
|
videodata vd;
|
|
if(!query_videodata(database,&vd,"id = "+vid)||vd.status=='w'){
|
|
std::cout << "Status: 404 Not Found\r\n"
|
|
<< "Content-type:text/html\r\n\r\n"
|
|
<< "<html>\n"
|
|
<< "<head>\n"
|
|
<< "<meta charset=\"utf-8\">\n"
|
|
<< "<title>安岛百合视频站</title>\n"
|
|
<< "</head>\n"
|
|
<< "<body>\n"
|
|
<< "<h1>视频不见了</h1>\n"
|
|
<< "视频可能未通过审核或不存在\n"
|
|
<< "</body>\n"
|
|
<< "</html>\n";
|
|
return 0;
|
|
}
|
|
std::cout << "Content-type:text/html\r\n\r\n"
|
|
<< "<!DOCTYPE html>\n"
|
|
<< "<html lang=\"zh-CN\">\n"
|
|
<< "<head>\n"
|
|
<< "<meta charset=\"UTF-8\">\n"
|
|
<< "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n"
|
|
<< "<title>"<<vd.title<<" - 🌸安岛百合视频站🌸</title>\n"
|
|
<< "<style>\n"
|
|
<< "* { margin: 0; padding: 0; box-sizing: border-box; }\n"
|
|
<< "body { \n"
|
|
<< " font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; \n"
|
|
<< " background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);\n"
|
|
<< " min-height: 100vh;\n"
|
|
<< " color: #333;\n"
|
|
<< " line-height: 1.6;\n"
|
|
<< "}\n"
|
|
<< ".container { \n"
|
|
<< " max-width: 1400px; \n"
|
|
<< " margin: 0 auto; \n"
|
|
<< " padding: 20px; \n"
|
|
<< "}\n"
|
|
<< ".video-header {\n"
|
|
<< " background: white;\n"
|
|
<< " padding: 30px;\n"
|
|
<< " border-radius: 15px 15px 0 0;\n"
|
|
<< " box-shadow: 0 4px 15px rgba(0,0,0,0.1);\n"
|
|
<< " margin-bottom: 0;\n"
|
|
<< "}\n"
|
|
<< ".video-header h1 {\n"
|
|
<< " color: #2d3748;\n"
|
|
<< " font-size: 2.2rem;\n"
|
|
<< " font-weight: 600;\n"
|
|
<< " margin-bottom: 15px;\n"
|
|
<< "}\n"
|
|
<< ".video-header p {\n"
|
|
<< " color: #718096;\n"
|
|
<< " font-size: 1.1rem;\n"
|
|
<< " line-height: 1.6;\n"
|
|
<< "}\n"
|
|
<< ".video-player {\n"
|
|
<< " background: #000;\n"
|
|
<< " border-radius: 0 0 15px 15px;\n"
|
|
<< " overflow: hidden;\n"
|
|
<< " box-shadow: 0 10px 30px rgba(0,0,0,0.3);\n"
|
|
<< " margin-bottom: 30px;\n"
|
|
<< "}\n"
|
|
<< ".video-player iframe {\n"
|
|
<< " width: 100%;\n"
|
|
<< " height: 720px;\n"
|
|
<< " border: none;\n"
|
|
<< " display: block;\n"
|
|
<< "}\n"
|
|
<< "/* 视频列表样式 */\n"
|
|
<< ".video-list {\n"
|
|
<< " background: white;\n"
|
|
<< " border-radius: 15px;\n"
|
|
<< " padding: 25px;\n"
|
|
<< " margin-bottom: 30px;\n"
|
|
<< " box-shadow: 0 4px 15px rgba(0,0,0,0.1);\n"
|
|
<< "}\n"
|
|
<< ".video-list h2 {\n"
|
|
<< " color: #2d3748;\n"
|
|
<< " font-size: 1.5rem;\n"
|
|
<< " margin-bottom: 20px;\n"
|
|
<< " padding-bottom: 10px;\n"
|
|
<< " border-bottom: 2px solid #e2e8f0;\n"
|
|
<< "}\n"
|
|
<< ".video-list ul {\n"
|
|
<< " list-style: none;\n"
|
|
<< " display: grid;\n"
|
|
<< " grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));\n"
|
|
<< " gap: 12px;\n"
|
|
<< "}\n"
|
|
<< ".video-list li {\n"
|
|
<< " margin-bottom: 0;\n"
|
|
<< "}\n"
|
|
<< ".video-list a {\n"
|
|
<< " display: block;\n"
|
|
<< " padding: 12px 16px;\n"
|
|
<< " background: #f7fafc;\n"
|
|
<< " border-radius: 8px;\n"
|
|
<< " text-decoration: none;\n"
|
|
<< " color: #4a5568;\n"
|
|
<< " transition: all 0.3s ease;\n"
|
|
<< " border-left: 3px solid #667eea;\n"
|
|
<< "}\n"
|
|
<< ".video-list a:hover {\n"
|
|
<< " background: #667eea;\n"
|
|
<< " color: white;\n"
|
|
<< " transform: translateX(5px);\n"
|
|
<< "}\n"
|
|
<< ".video-list .current-video {\n"
|
|
<< " background: #edf2f7;\n"
|
|
<< " color: #2d3748;\n"
|
|
<< " border-left: 3px solid #764ba2;\n"
|
|
<< " cursor: default;\n"
|
|
<< "}\n"
|
|
<< ".video-list .current-video:hover {\n"
|
|
<< " background: #edf2f7;\n"
|
|
<< " color: #2d3748;\n"
|
|
<< " transform: none;\n"
|
|
<< "}\n"
|
|
<< ".back-link {\n"
|
|
<< " text-align: center;\n"
|
|
<< " margin-top: 20px;\n"
|
|
<< "}\n"
|
|
<< ".back-link a {\n"
|
|
<< " color: white;\n"
|
|
<< " text-decoration: none;\n"
|
|
<< " font-size: 1.1rem;\n"
|
|
<< " padding: 10px 20px;\n"
|
|
<< " background: rgba(255,255,255,0.2);\n"
|
|
<< " border-radius: 25px;\n"
|
|
<< " transition: all 0.3s ease;\n"
|
|
<< "}\n"
|
|
<< ".back-link a:hover {\n"
|
|
<< " background: rgba(255,255,255,0.3);\n"
|
|
<< " transform: translateY(-2px);\n"
|
|
<< "}\n"
|
|
<< "@media (max-width: 768px) {\n"
|
|
<< " .video-player iframe {\n"
|
|
<< " height: 400px;\n"
|
|
<< " }\n"
|
|
<< " .video-header h1 {\n"
|
|
<< " font-size: 1.8rem;\n"
|
|
<< " }\n"
|
|
<< " .video-header {\n"
|
|
<< " padding: 20px;\n"
|
|
<< " }\n"
|
|
<< " .video-list ul {\n"
|
|
<< " grid-template-columns: 1fr;\n"
|
|
<< " }\n"
|
|
<< "}\n"
|
|
<< "</style>\n"
|
|
<< "</head>\n"
|
|
<< "<body>\n"
|
|
<< "<div class=\"container\">\n"
|
|
<< " <div class=\"video-header\">\n"
|
|
<< " <h1>"<<vd.title<<"</h1>\n"
|
|
<< " <p>"<<vd.description<<"</p>\n"
|
|
<< " </div>\n"
|
|
<< " <div class=\"video-player\">\n"
|
|
<< " <iframe src=\"/player.html?id="<<vid<<"\" allowfullscreen></iframe>\n"
|
|
<< " </div>\n";
|
|
if(vd.collection!=0) {
|
|
std::cout << " <div class=\"video-list\">\n"
|
|
<< " <h2>📺 视频列表</h2>\n"
|
|
<< " <ul>\n";
|
|
std::vector<collectionlist> cl;
|
|
get_collection_list(database,&cl,vd.collection);
|
|
for(const auto& c : cl) {
|
|
videodata video;
|
|
query_videodata(database,&video,"id = "+std::to_string(c.vid));
|
|
if(video.id==vd.id) {
|
|
std::cout << " <li><span class=\"current-video\">▶ " << video.title << " (正在播放)</span></li>\n";
|
|
} else {
|
|
std::cout << " <li><a href=\"/video/?v=" << video.id << "\">" << video.title << "</a></li>\n";
|
|
}
|
|
}
|
|
std::cout << " </ul>\n"
|
|
<< " </div>\n";
|
|
}
|
|
std::cout << " <div class=\"back-link\">\n"
|
|
<< " <a href=\"/\">← 返回首页</a>\n"
|
|
<< " </div>\n"
|
|
<< "</div>\n"
|
|
<< "</body>\n"
|
|
<< "</html>\n";
|
|
}
|
|
return 0;
|
|
} |