-
Notifications
You must be signed in to change notification settings - Fork 0
[codex] Add authenticated cloud file uploads #698
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c930ab9
Add authenticated cloud file uploads
fernandotonon 91ecdc3
fix(tests): link CloudUploadPlanner into MaterialEditorQML test targets
fernandotonon 0543ced
fix(cloud): project picker, abortable uploads, and review fixes
fernandotonon 2ebcbd0
Merge branch 'master' into codex/cloud-authenticated-uploads
fernandotonon 73c6d18
fix(cloud): reject malformed fetchProjects responses
fernandotonon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| #include "CloudUploadPlanner.h" | ||
|
|
||
| #include <QFileInfo> | ||
| #include <QMimeDatabase> | ||
| #include <QRegularExpression> | ||
| #include <QSet> | ||
|
|
||
| namespace { | ||
|
|
||
| bool hasExtension(const QString& ext, const QSet<QString>& extensions) | ||
| { | ||
| return extensions.contains(ext.toLower()); | ||
| } | ||
|
|
||
| } // namespace | ||
|
|
||
| QString CloudUploadPlanner::makeProjectSlug(const QString& name, const QString& fallback) | ||
| { | ||
| auto normalize = [](const QString& value) { | ||
| QString slug = value.trimmed().toLower(); | ||
| slug.replace(QRegularExpression(QStringLiteral("[^a-z0-9]+")), QStringLiteral("-")); | ||
| slug.replace(QRegularExpression(QStringLiteral("^-+|-+$")), QString()); | ||
| slug.replace(QRegularExpression(QStringLiteral("-{2,}")), QStringLiteral("-")); | ||
| return slug; | ||
| }; | ||
|
|
||
| QString slug = normalize(name); | ||
| if (slug.isEmpty()) | ||
| slug = normalize(fallback); | ||
| if (slug.isEmpty()) | ||
| slug = QStringLiteral("qtmesh-project"); | ||
| if (slug.size() > 64) { | ||
| slug.truncate(64); | ||
| slug.replace(QRegularExpression(QStringLiteral("-+$")), QString()); | ||
| } | ||
| return slug; | ||
| } | ||
|
|
||
| QString CloudUploadPlanner::inferAssetRole(const QString& fileName) | ||
| { | ||
| const QString ext = QFileInfo(fileName).suffix().toLower(); | ||
| if (hasExtension(ext, {QStringLiteral("mesh"), QStringLiteral("obj"), QStringLiteral("fbx"), | ||
| QStringLiteral("gltf"), QStringLiteral("glb"), QStringLiteral("dae"), | ||
| QStringLiteral("collada"), QStringLiteral("stl"), QStringLiteral("tmd")})) | ||
| return QStringLiteral("model"); | ||
| if (hasExtension(ext, {QStringLiteral("skeleton"), QStringLiteral("skel")})) | ||
| return QStringLiteral("skeleton"); | ||
| if (hasExtension(ext, {QStringLiteral("anim"), QStringLiteral("animation")})) | ||
| return QStringLiteral("animation"); | ||
| if (hasExtension(ext, {QStringLiteral("material"), QStringLiteral("mat"), QStringLiteral("mtl")})) | ||
| return QStringLiteral("material"); | ||
| if (hasExtension(ext, {QStringLiteral("png"), QStringLiteral("jpg"), QStringLiteral("jpeg"), | ||
| QStringLiteral("tga"), QStringLiteral("bmp"), QStringLiteral("dds"), | ||
| QStringLiteral("tif"), QStringLiteral("tiff"), QStringLiteral("tim")})) | ||
| return QStringLiteral("texture"); | ||
| if (hasExtension(ext, {QStringLiteral("json"), QStringLiteral("yml"), QStringLiteral("yaml"), | ||
| QStringLiteral("xml")})) | ||
| return QStringLiteral("metadata"); | ||
| if (hasExtension(ext, {QStringLiteral("rsd"), QStringLiteral("ply")})) | ||
| return QStringLiteral("sidecar"); | ||
| return QStringLiteral("file"); | ||
| } | ||
|
|
||
| QList<QtMeshCloudClient::AssetFileDescriptor> | ||
| CloudUploadPlanner::buildAssetFileDescriptors(const QStringList& paths) | ||
| { | ||
| QList<QtMeshCloudClient::AssetFileDescriptor> descriptors; | ||
| QMimeDatabase mimeDatabase; | ||
| for (const QString& path : paths) { | ||
| const QFileInfo info(path); | ||
| QtMeshCloudClient::AssetFileDescriptor descriptor; | ||
| descriptor.path = path; | ||
| descriptor.uploadName = info.fileName(); | ||
| descriptor.role = inferAssetRole(info.fileName()); | ||
| descriptor.mimeType = mimeDatabase.mimeTypeForFile(info, QMimeDatabase::MatchExtension).name(); | ||
| descriptor.sizeBytes = info.size(); | ||
| descriptors.append(descriptor); | ||
| } | ||
| return descriptors; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| #ifndef CLOUD_UPLOAD_PLANNER_H | ||
| #define CLOUD_UPLOAD_PLANNER_H | ||
|
|
||
| #include "QtMeshCloudClient.h" | ||
|
|
||
| #include <QString> | ||
| #include <QStringList> | ||
|
|
||
| namespace CloudUploadPlanner { | ||
|
|
||
| QString makeProjectSlug(const QString& name, const QString& fallback = QStringLiteral("qtmesh-project")); | ||
| QString inferAssetRole(const QString& fileName); | ||
| QList<QtMeshCloudClient::AssetFileDescriptor> buildAssetFileDescriptors(const QStringList& paths); | ||
|
|
||
| } // namespace CloudUploadPlanner | ||
|
|
||
| #endif // CLOUD_UPLOAD_PLANNER_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| #include "CloudUploadPlanner.h" | ||
|
|
||
| #include <gtest/gtest.h> | ||
|
|
||
| #include <QTemporaryDir> | ||
| #include <QFile> | ||
|
|
||
| TEST(CloudUploadPlanner, MakesStableSlug) | ||
| { | ||
| EXPECT_EQ(CloudUploadPlanner::makeProjectSlug(QStringLiteral(" My PS1 Asset Pack!! ")), | ||
| QStringLiteral("my-ps1-asset-pack")); | ||
| EXPECT_EQ(CloudUploadPlanner::makeProjectSlug(QStringLiteral("###"), QStringLiteral("Fallback Name")), | ||
| QStringLiteral("fallback-name")); | ||
| } | ||
|
|
||
| TEST(CloudUploadPlanner, TruncatesSlugWithoutTrailingDash) | ||
| { | ||
| const QString slug = CloudUploadPlanner::makeProjectSlug( | ||
| QStringLiteral("abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz")); | ||
| EXPECT_LE(slug.size(), 64); | ||
| EXPECT_FALSE(slug.endsWith(QLatin1Char('-'))); | ||
| } | ||
|
|
||
| TEST(CloudUploadPlanner, CollisionSuffixStaysWithinLimit) | ||
| { | ||
| const QString longName = QStringLiteral( | ||
| "abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz"); | ||
| const QString retrySlug = CloudUploadPlanner::makeProjectSlug( | ||
| QStringLiteral("%1-%2").arg(longName, QStringLiteral("20260529140530"))); | ||
| EXPECT_LE(retrySlug.size(), 64); | ||
| EXPECT_FALSE(retrySlug.endsWith(QLatin1Char('-'))); | ||
| } | ||
|
|
||
| TEST(CloudUploadPlanner, InfersKnownAssetRoles) | ||
| { | ||
| EXPECT_EQ(CloudUploadPlanner::inferAssetRole(QStringLiteral("model.FBX")), QStringLiteral("model")); | ||
| EXPECT_EQ(CloudUploadPlanner::inferAssetRole(QStringLiteral("rig.skeleton")), QStringLiteral("skeleton")); | ||
| EXPECT_EQ(CloudUploadPlanner::inferAssetRole(QStringLiteral("walk.anim")), QStringLiteral("animation")); | ||
| EXPECT_EQ(CloudUploadPlanner::inferAssetRole(QStringLiteral("wall.TIM")), QStringLiteral("texture")); | ||
| EXPECT_EQ(CloudUploadPlanner::inferAssetRole(QStringLiteral("stage.RSD")), QStringLiteral("sidecar")); | ||
| EXPECT_EQ(CloudUploadPlanner::inferAssetRole(QStringLiteral("metadata.json")), QStringLiteral("metadata")); | ||
| EXPECT_EQ(CloudUploadPlanner::inferAssetRole(QStringLiteral("notes.txt")), QStringLiteral("file")); | ||
| } | ||
|
|
||
| TEST(CloudUploadPlanner, BuildsDescriptorsFromPaths) | ||
| { | ||
| QTemporaryDir dir; | ||
| ASSERT_TRUE(dir.isValid()); | ||
| const QString path = dir.filePath(QStringLiteral("cube.obj")); | ||
| QFile file(path); | ||
| ASSERT_TRUE(file.open(QIODevice::WriteOnly)); | ||
| ASSERT_EQ(file.write("data"), 4); | ||
| file.close(); | ||
|
|
||
| const auto descriptors = CloudUploadPlanner::buildAssetFileDescriptors({path}); | ||
| ASSERT_EQ(descriptors.size(), 1); | ||
| EXPECT_EQ(descriptors.first().path, path); | ||
| EXPECT_EQ(descriptors.first().uploadName, QStringLiteral("cube.obj")); | ||
| EXPECT_EQ(descriptors.first().role, QStringLiteral("model")); | ||
| EXPECT_EQ(descriptors.first().sizeBytes, 4); | ||
| EXPECT_FALSE(descriptors.first().mimeType.isEmpty()); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.