Skip to content

Commit

Permalink
fix: Updated Metadata Upload feature with compatible format
Browse files Browse the repository at this point in the history
  • Loading branch information
saszer committed May 20, 2022
1 parent 8a10475 commit 83938c1
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 24 deletions.
33 changes: 33 additions & 0 deletions Runtime/Internal/ProcessMetadataToUpload.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@

using System.Collections.Generic;

namespace NFTPort.Internal
{

/// <summary>
/// To Process custom field attributes list
/// </summary>
public static class ProcessMetadataToUpload
{
public static Storage_MetadataToUpload_processedModel ConvertCustomFieldsListToDict(Storage_MetadataToUpload_model metadata)
{
Dictionary<string, string> dctn = new Dictionary<string, string>();
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;
}
}
}

11 changes: 11 additions & 0 deletions Runtime/Internal/ProcessMetadataToUpload.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions Runtime/Internal/Storage_MetadataToUpload_processedModel.cs
Original file line number Diff line number Diff line change
@@ -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<string, string> custom_fields;

[DefaultValue(null)]
public List<Attribute> attributes;

}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 21 additions & 21 deletions Runtime/Internal/models/Storage_MetadataToUpload_model.cs
Original file line number Diff line number Diff line change
@@ -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<Trait> traits;
[DefaultValue(null)]
public List<Attribute> 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> custom_fields;

[DefaultValue(null)]
public List<Attribute> attributes;

}

[Serializable]
public class custom_fields
{
public string key;
public string value;
}
}

9 changes: 7 additions & 2 deletions Runtime/Storage_UploadMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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:")]
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit 83938c1

Please sign in to comment.