Skip to content

Commit 4e948ee

Browse files
minor style changes and version bump
1 parent 2e53e97 commit 4e948ee

File tree

7 files changed

+87
-70
lines changed

7 files changed

+87
-70
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ build/
33
*.elf
44
*.nacp
55
*.nro
6-
.vscode
6+
.vscode

Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,13 @@ include $(DEVKITPRO)/libnx/switch_rules
3838
# NACP building is skipped as well.
3939
#---------------------------------------------------------------------------------
4040
APP_TITLE := ShareNX
41-
APP_VERSION := 1.0.1
41+
APP_VERSION := 1.1.0
4242

4343
TARGET := ovlShareNX
4444
BUILD := build
4545
SOURCES := source
4646
DATA := data
4747
INCLUDES := libs/include
48-
APP_VERSION := 1.1.0
4948

5049
ifeq ($(RELEASE),)
5150
APP_VERSION := $(APP_VERSION)-$(shell git describe --dirty --always)

source/gui_error.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ tsl::elm::Element *ErrorGui::createUI() {
3333
auto *custom = new tsl::elm::CustomDrawer([&](tsl::gfx::Renderer *drawer, u16 x, u16 y, u16 w, u16 h) {
3434
static s32 msg_width = 0;
3535
if (msg_width == 0) {
36-
auto [width ,height] = drawer->drawString(this->m_msg, false, 0, 0, 25, tsl::style::color::ColorTransparent);
36+
auto [width, height] = drawer->drawString(this->m_msg, false, 0, 0, 25, tsl::style::color::ColorTransparent);
3737
msg_width = width;
3838
}
3939
drawer->drawString("\uE150", false, x + ((w - 90) / 2), 300, 90, 0xffff);

source/gui_main.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,3 @@ tsl::elm::Element *MainGui::createUI() {
5252

5353
return rootFrame;
5454
}
55-

source/image_item.hpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
/*
2+
* Copyright (c) 2020 Behemoth
3+
*
4+
* This file is part of ShareNX.
5+
*
6+
* This program is free software; you can redistribute it and/or modify it
7+
* under the terms and conditions of the GNU General Public License,
8+
* version 2, as published by the Free Software Foundation.
9+
*
10+
* This program is distributed in the hope it will be useful, but WITHOUT
11+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13+
* more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*/
118
#pragma once
219

320
#include <tesla.hpp>
@@ -51,7 +68,7 @@ class ImageItem : public tsl::elm::ListItem {
5168
}
5269

5370
public:
54-
void setUrl(const std::string& url) {
71+
void setUrl(const std::string &url) {
5572
this->url = url;
5673
}
5774
};

source/upload.cpp

Lines changed: 64 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -19,78 +19,79 @@
1919

2020
#include <sys/select.h>
2121
#include <curl/curl.h>
22+
2223
#include <tesla.hpp>
2324

2425
namespace web {
2526

26-
size_t StringWrite(const char *contents, size_t size, size_t nmemb, std::string *userp) {
27-
userp->append(contents, size * nmemb);
28-
return size * nmemb;
29-
}
30-
31-
std::string UploadImage(const CapsAlbumFileId &fileId) {
32-
u64 size = 0;
33-
Result rc = capsaGetAlbumFileSize(&fileId, &size);
34-
if (R_FAILED(rc))
35-
return "can't get size";
36-
37-
void *imgBuffer = malloc(size);
38-
if (!imgBuffer)
39-
return "malloc failed";
40-
41-
u64 actualSize = 0;
42-
rc = capsaLoadAlbumFile(&fileId, &actualSize, imgBuffer, size);
43-
if (R_FAILED(rc)) {
44-
free(imgBuffer);
45-
return "failed to load img";
27+
size_t StringWrite(const char *contents, size_t size, size_t nmemb, std::string *userp) {
28+
userp->append(contents, size * nmemb);
29+
return size * nmemb;
4630
}
4731

48-
CURL *curl = curl_easy_init();
49-
if (!curl)
50-
return "failed to start curl";
51-
52-
curl_mime *mime = curl_mime_init(curl);
53-
curl_mimepart *file_part = curl_mime_addpart(mime);
54-
55-
curl_mime_filename(file_part, "switch.jpg");
56-
curl_mime_name(file_part, "fileToUpload");
57-
curl_mime_data(file_part, (const char *)imgBuffer, actualSize);
32+
std::string UploadImage(const CapsAlbumFileId &fileId) {
33+
u64 size = 0;
34+
Result rc = capsaGetAlbumFileSize(&fileId, &size);
35+
if (R_FAILED(rc))
36+
return "can't get size";
37+
38+
void *imgBuffer = malloc(size);
39+
if (!imgBuffer)
40+
return "malloc failed";
41+
42+
u64 actualSize = 0;
43+
rc = capsaLoadAlbumFile(&fileId, &actualSize, imgBuffer, size);
44+
if (R_FAILED(rc)) {
45+
free(imgBuffer);
46+
return "failed to load img";
47+
}
48+
49+
CURL *curl = curl_easy_init();
50+
if (!curl)
51+
return "failed to start curl";
52+
53+
curl_mime *mime = curl_mime_init(curl);
54+
curl_mimepart *file_part = curl_mime_addpart(mime);
55+
56+
curl_mime_filename(file_part, "switch.jpg");
57+
curl_mime_name(file_part, "fileToUpload");
58+
curl_mime_data(file_part, (const char *)imgBuffer, actualSize);
59+
60+
curl_mimepart *part = curl_mime_addpart(mime);
61+
curl_mime_name(part, "curl");
62+
curl_mime_data(part, "1", CURL_ZERO_TERMINATED);
63+
64+
std::string urlresponse = std::string();
65+
66+
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, StringWrite);
67+
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&urlresponse);
68+
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "POST");
69+
curl_easy_setopt(curl, CURLOPT_MIMEPOST, mime);
70+
curl_easy_setopt(curl, CURLOPT_URL, "https://lewd.pics/p/index.php");
71+
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
72+
73+
CURLcode res = CURLE_OK;
74+
tsl::hlp::doWithSmSession([&] {
75+
res = curl_easy_perform(curl);
76+
});
77+
78+
long http_code = 0;
79+
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_code);
80+
81+
if (res != CURLE_OK) {
82+
urlresponse = "curl failed " + std::to_string(res);
83+
} else if (http_code != 200) {
84+
urlresponse = "failed with " + std::to_string(http_code);
85+
} else if (urlresponse.size() > 0x30) {
86+
urlresponse = "result too long";
87+
}
5888

59-
curl_mimepart *part = curl_mime_addpart(mime);
60-
curl_mime_name(part, "curl");
61-
curl_mime_data(part, "1", CURL_ZERO_TERMINATED);
62-
63-
std::string urlresponse = std::string();
64-
65-
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, StringWrite);
66-
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&urlresponse);
67-
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "POST");
68-
curl_easy_setopt(curl, CURLOPT_MIMEPOST, mime);
69-
curl_easy_setopt(curl, CURLOPT_URL, "https://lewd.pics/p/index.php");
70-
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
71-
72-
CURLcode res = CURLE_OK;
73-
tsl::hlp::doWithSmSession([&]{
74-
res = curl_easy_perform(curl);
75-
});
89+
free(imgBuffer);
7690

77-
long http_code = 0;
78-
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_code);
91+
curl_mime_free(mime);
92+
curl_easy_cleanup(curl);
7993

80-
if (res != CURLE_OK) {
81-
urlresponse = "curl failed " + std::to_string(res);
82-
} else if (http_code != 200) {
83-
urlresponse = "failed with " + std::to_string(http_code);
84-
} else if (urlresponse.size() > 0x30) {
85-
urlresponse = "result too long";
94+
return urlresponse;
8695
}
8796

88-
free(imgBuffer);
89-
90-
curl_mime_free(mime);
91-
curl_easy_cleanup(curl);
92-
93-
return urlresponse;
94-
}
95-
9697
}

source/upload.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@
1717
*/
1818
#pragma once
1919

20-
#include <string>
2120
#include <switch.h>
2221

22+
#include <string>
23+
2324
namespace web {
2425

2526
std::string UploadImage(const CapsAlbumFileId &fileId);

0 commit comments

Comments
 (0)