From 83938c137d3a29d78d1eadf8c19e0cbf810fd5e2 Mon Sep 17 00:00:00 2001
From: "sz.sahaj" <43649755+saszer@users.noreply.github.com>
Date: Fri, 20 May 2022 16:37:19 +1000
Subject: [PATCH] fix: Updated Metadata Upload feature with compatible format
---
Runtime/Internal/ProcessMetadataToUpload.cs | 33 +++++++++++++++
.../Internal/ProcessMetadataToUpload.cs.meta | 11 +++++
...Storage_MetadataToUpload_processedModel.cs | 32 ++++++++++++++
...ge_MetadataToUpload_processedModel.cs.meta | 3 ++
.../models/Storage_MetadataToUpload_model.cs | 42 +++++++++----------
Runtime/Storage_UploadMetadata.cs | 9 +++-
package.json | 2 +-
7 files changed, 108 insertions(+), 24 deletions(-)
create mode 100644 Runtime/Internal/ProcessMetadataToUpload.cs
create mode 100644 Runtime/Internal/ProcessMetadataToUpload.cs.meta
create mode 100644 Runtime/Internal/Storage_MetadataToUpload_processedModel.cs
create mode 100644 Runtime/Internal/Storage_MetadataToUpload_processedModel.cs.meta
diff --git a/Runtime/Internal/ProcessMetadataToUpload.cs b/Runtime/Internal/ProcessMetadataToUpload.cs
new file mode 100644
index 0000000..79f6d76
--- /dev/null
+++ b/Runtime/Internal/ProcessMetadataToUpload.cs
@@ -0,0 +1,33 @@
+
+using System.Collections.Generic;
+
+namespace NFTPort.Internal
+{
+
+ ///
+ /// To Process custom field attributes list
+ ///
+ public static class ProcessMetadataToUpload
+ {
+ public static Storage_MetadataToUpload_processedModel ConvertCustomFieldsListToDict(Storage_MetadataToUpload_model metadata)
+ {
+ Dictionary dctn = new Dictionary();
+ Storage_MetadataToUpload_processedModel processedModel = new Storage_MetadataToUpload_processedModel();
+ foreach (var custom_field in metadata.custom_fields)
+ {
+ dctn.Add(custom_field.key, custom_field.value);
+ }
+
+ processedModel.animation_url = metadata.animation_url;
+ processedModel.attributes = metadata.attributes;
+ processedModel.custom_fields = dctn;
+ processedModel.description = metadata.description;
+ processedModel.external_url = metadata.external_url;
+ processedModel.name = metadata.name;
+ processedModel.file_url = metadata.file_url;
+
+ return processedModel;
+ }
+ }
+}
+
diff --git a/Runtime/Internal/ProcessMetadataToUpload.cs.meta b/Runtime/Internal/ProcessMetadataToUpload.cs.meta
new file mode 100644
index 0000000..2ded557
--- /dev/null
+++ b/Runtime/Internal/ProcessMetadataToUpload.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: afdf5b1f4cabba34ba133a0ec50ddac9
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Runtime/Internal/Storage_MetadataToUpload_processedModel.cs b/Runtime/Internal/Storage_MetadataToUpload_processedModel.cs
new file mode 100644
index 0000000..ba26d2d
--- /dev/null
+++ b/Runtime/Internal/Storage_MetadataToUpload_processedModel.cs
@@ -0,0 +1,32 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using UnityEngine;
+
+namespace NFTPort.Internal
+{
+ [Serializable]
+ public class Storage_MetadataToUpload_processedModel
+ {
+ [Tooltip("URL of the file that you wish to link with the metadata and turn into an NFT., use 'Storage File Upload' to get url")]
+ public string file_url = "Required Field";
+ public string name = "Required Field";
+ public string description = "Required Field";
+
+ [DefaultValue("")][Tooltip("URL that will appear below the NFT on some of the NFT marketplaces such as OpenSea.")]
+ public string external_url;
+
+ [DefaultValue("")][Tooltip("URL to a multimedia attachment with all filetypes supported. If you want to make sure the file is supported by OpenSea, then see their docs. When using animation_url, set the file_url as the multimedia preview which will be displayed on the NFT marketplaces e.g. if your animation_url is a video then set file_url as the preview image for it.")]
+ public string animation_url;
+
+ [DefaultValue(null)]
+ [Tooltip(
+ "Allows you to extend the metadata schema with your own arbitrary fields. You can pass anything here as long as it is follows “key”: “value” format inside a dictionary. All of the fields will be flattened and added to the top-level namespace e.g. like name, description, etc. ")]
+ public Dictionary custom_fields;
+
+ [DefaultValue(null)]
+ public List attributes;
+
+ }
+}
+
diff --git a/Runtime/Internal/Storage_MetadataToUpload_processedModel.cs.meta b/Runtime/Internal/Storage_MetadataToUpload_processedModel.cs.meta
new file mode 100644
index 0000000..dd81469
--- /dev/null
+++ b/Runtime/Internal/Storage_MetadataToUpload_processedModel.cs.meta
@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: 820c8fb8e2079f94180616c9ac9a2f3e
+timeCreated: 1652958434
\ No newline at end of file
diff --git a/Runtime/Internal/models/Storage_MetadataToUpload_model.cs b/Runtime/Internal/models/Storage_MetadataToUpload_model.cs
index b1ec9b8..c5d2db2 100644
--- a/Runtime/Internal/models/Storage_MetadataToUpload_model.cs
+++ b/Runtime/Internal/models/Storage_MetadataToUpload_model.cs
@@ -1,37 +1,37 @@
-using System.Collections;
+using System;
using System.Collections.Generic;
using System.ComponentModel;
-using System.Dynamic;
-using Newtonsoft.Json;
using UnityEngine;
namespace NFTPort
{
- [System.Serializable]
+ [Serializable]
public class Storage_MetadataToUpload_model
{
- [Tooltip("Main NFT File URL, use 'Storage File Upload' to get url")]
+ [Tooltip("URL of the file that you wish to link with the metadata and turn into an NFT., use 'Storage File Upload' to get url")]
public string file_url = "Required Field";
public string name = "Required Field";
public string description = "Required Field";
- [DefaultValue("-99")][Tooltip("Set to -99 to exclude in metadata")]
- public int edition;
- [DefaultValue(null)]
- public List traits;
- [DefaultValue(null)]
- public List attributes;
- [DefaultValue("")]
- public string compiler;
- [DefaultValue("")]
- public string background_color;
- [DefaultValue("")]
+
+ [DefaultValue("")][Tooltip("URL that will appear below the NFT on some of the NFT marketplaces such as OpenSea.")]
public string external_url;
- [DefaultValue("")]
+
+ [DefaultValue("")][Tooltip("URL to a multimedia attachment with all filetypes supported. If you want to make sure the file is supported by OpenSea, then see their docs. When using animation_url, set the file_url as the multimedia preview which will be displayed on the NFT marketplaces e.g. if your animation_url is a video then set file_url as the preview image for it.")]
public string animation_url;
- [DefaultValue("")]
- public string dna;
- [DefaultValue("")]
- public string id;
+
+ [DefaultValue(null)][Tooltip("Allows you to extend the metadata schema with your own arbitrary fields. You can pass anything here as long as it is follows “key”: “value” format inside a dictionary. All of the fields will be flattened and added to the top-level namespace e.g. like name, description, etc. ")]
+ public List custom_fields;
+
+ [DefaultValue(null)]
+ public List attributes;
+
+ }
+
+ [Serializable]
+ public class custom_fields
+ {
+ public string key;
+ public string value;
}
}
diff --git a/Runtime/Storage_UploadMetadata.cs b/Runtime/Storage_UploadMetadata.cs
index a3f667d..abcbaaf 100644
--- a/Runtime/Storage_UploadMetadata.cs
+++ b/Runtime/Storage_UploadMetadata.cs
@@ -41,6 +41,7 @@ public class Storage_UploadMetadata : MonoBehaviour
[Header("Run Component when this Game Object is Set Active")] [SerializeField]
private bool onEnable = false;
public bool debugErrorLog = true;
+ public bool debugLogRawJson = false;
public bool debugLogRawApiResponse = false;
[Header("Response after successful upload:")]
@@ -202,16 +203,20 @@ string BuildUrl()
IEnumerator CallAPIProcess()
{
//var _FormParams = FormMaker.Formeet(filePath);
+
+ var processedMetadata = ProcessMetadataToUpload.ConvertCustomFieldsListToDict(metadata);
string json = JsonConvert.SerializeObject(
- metadata,
+ processedMetadata,
new JsonSerializerSettings
{
DefaultValueHandling = DefaultValueHandling.Ignore,
NullValueHandling = NullValueHandling.Ignore
});
+ if (debugLogRawJson)
+ Debug.Log(json);
byte[] jsonToSend = new System.Text.UTF8Encoding().GetBytes(json);
-
+
request = new UnityWebRequest(WEB_URL, "POST");
UploadHandler uploader = new UploadHandlerRaw(jsonToSend);
//uploader.contentType = _FormParams.contentType;
diff --git a/package.json b/package.json
index 36a0d62..89069cf 100644
--- a/package.json
+++ b/package.json
@@ -1,7 +1,7 @@
{
"name": "com.nftport.nftport",
"displayName": "NFTPort",
- "version": "0.2.0-preview",
+ "version": "0.2.1-preview",
"description": "NFTPort.xyz unity extension provides tools and features to integrate NFT's crosschain at lightning speed in Unity.\n\n https://github.com/nftport/nftport-unity.git",
"type": "tool",
"documentationUrl": "https://docs.nftport.xyz/docs/nftport",