Skip to content

Commit

Permalink
添加OSS配置模块
Browse files Browse the repository at this point in the history
  • Loading branch information
akikohaku committed Oct 28, 2021
1 parent f462286 commit 14c2396
Show file tree
Hide file tree
Showing 4 changed files with 193 additions and 19 deletions.
14 changes: 7 additions & 7 deletions OSS.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ using namespace AlibabaCloud::OSS;

class oss{
public:
QString upload(QString filename,bool isOn){
std::string AccessKeyId = "";
std::string AccessKeySecret = "";
std::string Endpoint = "oss-cn-shanghai.aliyuncs.com";
QString upload(QString filename,bool isOn,QString keyid,QString secret,QString endpoint,QString bucket,QString path){
std::string AccessKeyId = keyid.toStdString();
std::string AccessKeySecret = secret.toStdString();
std::string Endpoint = endpoint.toStdString();
/* 填写Bucket名称,例如examplebucket */
std::string BucketName = "";
std::string BucketName = bucket.toStdString();
/* 填写文件完整路径,例如exampledir/exampleobject.txt。文件完整路径中不能包含Bucket名称 */
std::string ObjectName = "web/pic/"+getFileMd5(filename).toStdString()+"."+filename.split(".").last().toStdString();
std::string ObjectName = path.toStdString()+getFileMd5(filename).toStdString()+"."+filename.split(".").last().toStdString();

if(isOn){
/* 初始化网络等资源 */
Expand All @@ -42,7 +42,7 @@ class oss{
/* 释放网络等资源 */
ShutdownSdk();
}
QString webpath=""+getFileMd5(filename)+"."+filename.split(".").last();
QString webpath="https://"+bucket+"."+endpoint+"/"+path+getFileMd5(filename)+"."+filename.split(".").last();
return webpath;
}
private:
Expand Down
37 changes: 34 additions & 3 deletions mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,24 @@ MainWindow::MainWindow(QWidget *parent)
std::locale::global(std::locale(""));
QString str = "中文";
std::cout << str.toLocal8Bit().data();
QFile file(QCoreApplication::applicationDirPath()+"/OSS.config");
if (file.open(QIODevice::ReadOnly | QIODevice::Text))
{
QTextStream stream(&file);
QList<QByteArray> temp=QList<QByteArray>();
while (!file.atEnd()){
temp.append(file.readLine());
qDebug() << str;
}
ui->keyID->setText(temp.at(0).split('\n').at(0));
ui->lineEdit_4->setText(temp.at(1).split('\n').at(0));
ui->lineEdit_5->setText(temp.at(2).split('\n').at(0));
ui->lineEdit_6->setText(temp.at(3).split('\n').at(0));
ui->lineEdit_7->setText(temp.at(4).split('\n').at(0));
file.close();
}else{
ui->textEdit->append("[System]:读取OSS文件失败,请先配置OSS");
}
}

MainWindow::~MainWindow()
Expand Down Expand Up @@ -198,7 +216,7 @@ void MainWindow::on_analize_clicked()
outfile.open((golbal.SaveFile+QString::number(golbal.count)+" - "+filename.split("/").last().split(".").first()+".md").toLocal8Bit(),std::ios::out);
ui->textEdit->append("[System]:创建文件 "+golbal.SaveFile+QString::number(golbal.count)+" - "+filename.split("/").last().split(".").first()+".md");
oss uploader;
QString out = uploader.upload(QCoreApplication::applicationDirPath()+"/cache/OEBPS/"+filename,!ui->disableupload->isChecked());
QString out = uploader.upload(QCoreApplication::applicationDirPath()+"/cache/OEBPS/"+filename,!ui->disableupload->isChecked(),ui->keyID->text(),ui->lineEdit_4->text(),ui->lineEdit_5->text(),ui->lineEdit_6->text(),ui->lineEdit_7->text());
outfile<<"![]("<<out.toStdString()<<")"<<std::endl;
golbal.count++;
}else{
Expand Down Expand Up @@ -320,7 +338,7 @@ void MainWindow::on_analize_clicked()
QString picdir=QCoreApplication::applicationDirPath()+"/cache/OEBPS/Images"+strSRC.replace(QRegExp("../Images"),"");
//ui->textEdit->append(picdir);
oss uploader;
QString webpath=uploader.upload(picdir,!ui->disableupload->isChecked());
QString webpath=uploader.upload(picdir,!ui->disableupload->isChecked(),ui->keyID->text(),ui->lineEdit_4->text(),ui->lineEdit_5->text(),ui->lineEdit_6->text(),ui->lineEdit_7->text());
outfile << "![]("<<webpath.toStdString()<<")" <<std::endl;
}
}
Expand All @@ -338,7 +356,7 @@ void MainWindow::on_analize_clicked()
QString picdir=QCoreApplication::applicationDirPath()+"/cache/OEBPS/Images"+strSRC.replace(QRegExp("../Images"),"");
//ui->textEdit->append(picdir);
oss uploader;
QString webpath=uploader.upload(picdir,!ui->disableupload->isChecked());
QString webpath=uploader.upload(picdir,!ui->disableupload->isChecked(),ui->keyID->text(),ui->lineEdit_4->text(),ui->lineEdit_5->text(),ui->lineEdit_6->text(),ui->lineEdit_7->text());
outfile << "![]("<<webpath.toStdString()<<")" <<std::endl;
}
}
Expand Down Expand Up @@ -432,3 +450,16 @@ void MainWindow::on_H5_clicked()
ui->h4->setText("#");
ui->h5->setText("#");
}

void MainWindow::on_pushButton_2_clicked()
{
//保存OSS参数
std::fstream outfile;
outfile.open((QCoreApplication::applicationDirPath()+"/OSS.config").toLocal8Bit(),std::ios::out);
outfile <<ui->keyID->text().toStdString()<<std::endl;
outfile <<ui->lineEdit_4->text().toStdString()<<std::endl;
outfile <<ui->lineEdit_5->text().toStdString()<<std::endl;
outfile <<ui->lineEdit_6->text().toStdString()<<std::endl;
outfile <<ui->lineEdit_7->text().toStdString()<<std::endl;
ui->textEdit->append("[System]:已保存OSS参数");
}
2 changes: 2 additions & 0 deletions mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ private slots:

void on_H5_clicked();

void on_pushButton_2_clicked();

private:
Ui::MainWindow *ui;
values golbal;
Expand Down
159 changes: 150 additions & 9 deletions mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>800</width>
<height>600</height>
<height>647</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -103,9 +103,9 @@
<property name="geometry">
<rect>
<x>20</x>
<y>320</y>
<y>450</y>
<width>761</width>
<height>221</height>
<height>151</height>
</rect>
</property>
</widget>
Expand Down Expand Up @@ -346,8 +346,8 @@
<widget class="QCheckBox" name="unsettitle">
<property name="geometry">
<rect>
<x>200</x>
<y>240</y>
<x>30</x>
<y>295</y>
<width>231</width>
<height>21</height>
</rect>
Expand All @@ -359,8 +359,8 @@
<widget class="QCheckBox" name="useopf">
<property name="geometry">
<rect>
<x>200</x>
<y>270</y>
<x>30</x>
<y>325</y>
<width>181</width>
<height>16</height>
</rect>
Expand All @@ -372,8 +372,8 @@
<widget class="QCheckBox" name="connectedopf">
<property name="geometry">
<rect>
<x>200</x>
<y>295</y>
<x>30</x>
<y>350</y>
<width>161</width>
<height>21</height>
</rect>
Expand All @@ -382,6 +382,147 @@
<string>连接式opf</string>
</property>
</widget>
<widget class="QLineEdit" name="keyID">
<property name="geometry">
<rect>
<x>270</x>
<y>265</y>
<width>211</width>
<height>20</height>
</rect>
</property>
</widget>
<widget class="QLabel" name="keyid">
<property name="geometry">
<rect>
<x>223</x>
<y>265</y>
<width>61</width>
<height>21</height>
</rect>
</property>
<property name="text">
<string>KeyId</string>
</property>
</widget>
<widget class="QLineEdit" name="lineEdit_4">
<property name="geometry">
<rect>
<x>270</x>
<y>295</y>
<width>211</width>
<height>20</height>
</rect>
</property>
</widget>
<widget class="QLabel" name="secret">
<property name="geometry">
<rect>
<x>223</x>
<y>295</y>
<width>61</width>
<height>21</height>
</rect>
</property>
<property name="text">
<string>Secret</string>
</property>
</widget>
<widget class="QLineEdit" name="lineEdit_5">
<property name="geometry">
<rect>
<x>270</x>
<y>325</y>
<width>211</width>
<height>20</height>
</rect>
</property>
</widget>
<widget class="QLabel" name="endpoint">
<property name="geometry">
<rect>
<x>223</x>
<y>326</y>
<width>51</width>
<height>21</height>
</rect>
</property>
<property name="text">
<string>EndPoint</string>
</property>
</widget>
<widget class="QLineEdit" name="lineEdit_6">
<property name="geometry">
<rect>
<x>270</x>
<y>355</y>
<width>211</width>
<height>20</height>
</rect>
</property>
</widget>
<widget class="QLabel" name="bucket">
<property name="geometry">
<rect>
<x>223</x>
<y>355</y>
<width>51</width>
<height>21</height>
</rect>
</property>
<property name="text">
<string>Bucket</string>
</property>
</widget>
<widget class="QLineEdit" name="lineEdit_7">
<property name="geometry">
<rect>
<x>270</x>
<y>385</y>
<width>211</width>
<height>20</height>
</rect>
</property>
</widget>
<widget class="QLabel" name="path">
<property name="geometry">
<rect>
<x>223</x>
<y>385</y>
<width>51</width>
<height>20</height>
</rect>
</property>
<property name="text">
<string>Path</string>
</property>
</widget>
<widget class="QLabel" name="label_8">
<property name="geometry">
<rect>
<x>220</x>
<y>240</y>
<width>111</width>
<height>21</height>
</rect>
</property>
<property name="text">
<string>阿里云OSS配置</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_2">
<property name="geometry">
<rect>
<x>270</x>
<y>410</y>
<width>75</width>
<height>31</height>
</rect>
</property>
<property name="text">
<string>保存</string>
</property>
</widget>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
Expand Down

0 comments on commit 14c2396

Please sign in to comment.