Giving random name to a file before the POST method - javascript

I have an issue with the Postman/Node.js as in when I try to do POST method with a document attached. I want to change the name of the file before the request because two files of the same name cannot be uploaded. I want to be able to set it up so a collection can be run by anytime by my colleges. I did a workaround for Postman from http://blog.getpostman.com/2017/09/21/run-collections-with-file-uploads-using-newman/ for the file upload automatization.
My question is:
How can I take the file, change its name to something random, like test{{$timestamp}}.docx and point to the new name in that .json file again so it can be uploaded?
This is my .json file
{
"name": "Save case's documents CID CDN",
"event": [
{
"listen": "test",
"script": {
"id": "04bf1f30-c2bc-4250-97c9-9efb7afa25e3",
"type": "text/javascript",
"exec": [
"// Check the status of a request",
"pm.test(\"Addition of a document successful!\", function () {",
" pm.response.to.have.status(200);",
"});",
"// Check the response time ",
"pm.test(\"Response time is acceptable\", function () {",
" pm.expect(pm.response.responseTime).to.be.below(2000);",
"});",
"// Set documentName variable",
"var jsonData = JSON.parse(responseBody);",
"postman.setEnvironmentVariable(\"documentName\", jsonData.content.documentName);"
]
}
},
{
"listen": "prerequest",
"script": {
"id": "09a922cd-6c2a-47cb-b597-d5dcab0d45bd",
"type": "text/javascript",
"exec": [
"",
""
]
}
}
],
"request": {
"auth": {
"type": "bearer",
"bearer": [
{
"key": "token",
"value": "",
"type": "string"
}
]
},
"method": "POST",
"header": [
{
"key": "Authorization",
"value": "{{token}}"
},
{
"key": "Content-Type",
"value": "application/x-www-form-urlencoded"
}
],
"body": {
"mode": "formdata",
"formdata": [
{
"key": "document",
"value":
"C:\\Users\\User123456\\Desktop\\test.docx",
"description": "",
"type": "file",
"src": "C:\\Users\\User123456\\Desktop\\test.docx"
},
{
"key": "documentCategory",
"value": "Other",
"description": "",
"type": "text"
},
{
"key": "refCreatedBy",
"value": "{{bu_id}}",
"description": "",
"type": "text"
},
{
"key": "createdAt",
"value": "{{date}}",
"description": "",
"type": "text"
},
{
"key": "accuracy.status",
"value": "string",
"description": "",
"type": "text"
},
{
"key": "accuracy.lastModifiedDate",
"value": "{{$timestamp}}",
"description": "",
"type": "text"
},
{
"key": "accuracy.lastModifiedBy",
"value": "{{bu_id}}",
"description": "",
"type": "text"
},
{
"key": "quality.status",
"value": "sting",
"description": "",
"type": "text"
},
{
"key": "quality.lastModifiedDate",
"value": "{{$timestamp}}",
"description": "",
"type": "text"
},
{
"key": "quality.lastModifiedBy",
"value": "{{$timestamp}}",
"description": "",
"type": "text"
}
]
},
"url": {
"raw": "{{site}}/cases/{{case_id}}/documents/{{documentName}}",
"host": [
"{{site}}"
],
"path": [
"cases",
"{{case_id}}",
"documents",
"{{documentName}}"
]
},
"description": ""
},
"response": []
}
]
}

Related

How to add "collection" field to metadata for Solana NFTs with Visual Studio Code

I'm trying to add the collection field (name and family) to my metadata using VSC. Not sure where to begin or how to do it. Any help appreciated. Thanks!
{
"name": "Solflare X NFT",
"symbol": "",
"description": "Celebratory Solflare NFT for the Solflare X launch",
"seller_fee_basis_points": 0,
"image": "https://www.arweave.net/abcd5678?ext=png",
"animation_url": "https://www.arweave.net/efgh1234?ext=mp4",
"external_url": "https://solflare.com",
"attributes": [
{ "trait_type": "web", "value": "yes" },
{ "trait_type": "mobile", "value": "yes" },
{ "trait_type": "extension", "value": "yes" }
],
"collection": { "name": "Solflare X NFT", "family": "Solflare" },
"properties": {
"files": [
{
"uri": "https://www.arweave.net/abcd5678?ext=png",
"type": "image/png"
},
{
"uri": "https://watch.videodelivery.net/9876jkl",
"type": "unknown",
"cdn": true
},
{ "uri": "https://www.arweave.net/efgh1234?ext=mp4", "type": "video/mp4" }
],
"category": "video",
"creators": [
{ "address": "SOLFLR15asd9d21325bsadythp547912501b", "share": 100 }
]
}
}

How can I take the data from choiceSet in adaptive cards

I want the data (i.e value inside choices array) inside the red choiseSet when selected and clicked on the btn, I kept an image and added action submit as action.submit as that's my usecase, I am pretty much confused how I can do that, Here's the card payload
{
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"type": "AdaptiveCard",
"version": "1.2",
"body": [
{
"type": "Input.ChoiceSet",
"id": "myColor2",
"style": "expanded",
"value": "1",
"choices": [
{
"title": "Red",
"value": "1"
}
]
},
{
"type": "Image",
"altText": "it's a image",
"url": "https://media.istockphoto.com/vectors/bhutanese-ngultrum-btn-vector-id1304476894",
"width": "100px",
"height": "100px",
"horizontalAlignment": "Left",
"selectAction": {
"type": "Action.Submit",
"id": "btn",
"title": "btn"
}
}
]
}
Once submitted by clicking on the icon, the bot should receive an activity of type message but with no text. The data you want is in the value property.
{
"activity": {
"channelData": {
"postBack": true,
"clientActivityID": "<REMOVED>",
"clientTimestamp": "2022-04-05T18:43:17.348Z"
},
"type": "message",
"value": {
"myColor2": "1"
},
"channelId": "emulator",
"from": {
"id": "<REMOVED>",
"name": "",
"role": "user"
},
"locale": "en-us",
"localTimestamp": "2022-04-05T11:43:17-07:00",
"localTimezone": "America/Los_Angeles",
"timestamp": "2022-04-05T18:43:17.408Z",
"id": "<REMOVED>",
"recipient": {
"id": "<REMOVED>",
"name": "Bot",
"role": "bot"
},
"conversation": {
"id": "<REMOVED>"
},
"serviceUrl": "http://localhost:3212"
},
"id": "<REMOVED>",
"timestamp": 1649184197408
}

JSON schema validate oneOf with condition

How can I set json schema validator for next objects?
They all have field account_id, but options is dependent on type.
In case of twitter it has list of tokens, each of those has four fields.
If type is instagram, than each token has only one field in
tokens.
And for facebook type field options must be empty.
{
"type": "twitter",
"account_id": "xyz",
"options": {
"tokens": [{
"access_token": "long string",
"access_token_secret": "long string",
"consumer_key": "long string",
"consumer_secret": "long string"
}]
}
}
{
"type": "instagram",
"account_id": "xyz",
"options": {
"tokens": [{
"access_token": "long string"
}]
}
}
{
"type": "facebook",
"account_id": "xyz",
"options": {}
}
Is it possible to make json schema, that would satisfy those requirements? Even the most simple schema when definition for every type is wrapped in oneOf keywords does not work.
{
"type": "object",
"additionalProperties": false,
"oneOf": [{
"properties": {
"account_id": {
"type": "string",
},
"type": {
"const": "facebook"
},
"options": {
"type": "object",
"additionalProperties": false
}
},
"required": [
"account_id",
"type",
"options"
]
},
{
"type": "object",
"additionalProperties": false,
"properties": {
"account_id": {
"type": "string",
},
"type": {
"const": "twitter"
},
"options": {
"type": "array",
"items": {
"type": "object",
"additionalProperties": false,
"properties": {
"access_token": {
"type": "string"
},
"access_token_secret": {
"type": "string"
},
"consumer_key": {
"type": "string"
},
"consumer_secret": {
"type": "string"
}
},
"required": [
"access_token",
"access_token_secret",
"consumer_key",
"consumer_secret"
]
}
}
},
"required": [
"account_id",
"type",
"options"
]
},
{
"type": "object",
"additionalProperties": false,
"properties": {
"account_id": {
"type": "string",
},
"type": {
"const": "instagram"
},
"options": {
"type": "array",
"items": {
"type": "object",
"additionalProperties": false,
"properties": {
"access_token": {
"type": "string"
}
},
"required": [
"access_token"
]
}
}
},
"required": [
"account_id",
"type",
"options"
]
}
]
}
Thank you for any suggestions!

Angular Schema Form - arrayIndex as a parameter for button onClick

How can I pass the arrayIndex as a parameter to the function in onClick? Eg:
{
key:"someKey"
type:"array",
items:[
{
"key":"someKey[].itemNo"
},
{
"type":"button",
"onClick":"someFunction(someKey[arrayIndex].itemNo)"
}
]
}
arrayIndex in "condition" works. But in the function, undefined is what I am getting. I am able to access the entire model or the form's data in someFunction (i.e. i can access someKey), but I need access to the particular item in the array(i.e. someKey[index]).
UPDATED as requested:
(Taken from schema form example page)
See the performAction button. I need the email in the button's context to be passed into a function.
Form:
[
{
"key": "comments",
"add": "New",
"style": {
"add": "btn-success"
},
"items": [
"comments[].name",
"comments[].email",
{
"key": "comments[].spam",
"type": "checkbox",
"title": "Yes I want spam.",
"condition": "model.comments[arrayIndex].email"
},
{
"key": "comments[].comment",
"type": "textarea"
},
{
"type":"button",
"onClick":"performAction(comments[arrayIndex].email)",
"title":"Perform Action"
}
]
},
{
"type": "submit",
"style": "btn-info",
"title": "OK"
}
]
Schema:
{
"type": "object",
"title": "Comment",
"required": [
"comments"
],
"properties": {
"comments": {
"type": "array",
"maxItems": 2,
"items": {
"type": "object",
"properties": {
"name": {
"title": "Name",
"type": "string"
},
"email": {
"title": "Email",
"type": "string",
"pattern": "^\\S+#\\S+$",
"description": "Email will be used for evil."
},
"spam": {
"title": "Spam",
"type": "boolean",
"default": true
},
"comment": {
"title": "Comment",
"type": "string",
"maxLength": 20,
"validationMessage": "Don't be greedy!"
}
},
"required": [
"name",
"comment"
]
}
}
}
}
This was added in v1.0.0-alpha.1 with the addition of arrayIndices.

Adding IDs to Angular Schema Form's Input Fields?

I am using Angular Schema Form to generate input fields for me. I am wondering if there is any way I could customize the input fields by adding IDs. I tried looking at the documentation (https://github.com/Textalk/angular-schema-form/blob/development/docs/index.md), but it doesn't seem like the current version supports it (only adding classes).
I've just done a bit of research and on the "Kitchen Sink" Example on -
http://schemaform.io/examples/bootstrap-example.html
they have used this code
Form:
`[
{
"type": "fieldset",
"title": "Stuff",
"items": [
{
"type": "tabs",
"tabs": [
{
"title": "Simple stuff",
"items": [
{
"key": "name",
"placeholder": "Check the console",
"onChange": "log(modelValue)",
"feedback": "{'glyphicon': true, 'glyphicon-ok': hasSuccess(), 'glyphicon-star': !hasSuccess() }"
},
{
"key": "favorite",
"feedback": false
}
]
},
{
"title": "More stuff",
"items": [
"attributes.eyecolor",
"attributes.haircolor",
{
"key": "attributes.shoulders.left",
"title": "Left shoulder",
"description": "This value is copied to attributes.shoulders.right in the model",
"copyValueTo": [
"attributes.shoulders.right"
]
},
{
"key": "shoesizeLeft",
"feedback": false,
"copyValueTo": [
"shoesizeRight"
]
},
{
"key": "shoesizeRight"
},
{
"key": "invitation",
"tinymceOptions": {
"toolbar": [
"undo redo| styleselect | bold italic | link image",
"alignleft aligncenter alignright"
]
}
},
"things",
"dislike"
]
}
]
}
]
},
{
"type": "help",
"helpvalue": "<hr>"
},
"soul",
{
"type": "conditional",
"condition": "modelData.soul",
"items": [
{
"key": "soulserial",
"placeholder": "ex. 666"
}
]
},
{
"key": "date",
"minDate": "2014-06-20"
},
{
"key": "radio",
"type": "radios",
"titleMap": [
{
"value": "Transistor",
"name": "Transistor <br> Not the tube kind."
},
{
"value": "Tube",
"name": "Tube <br> The tube kind."
}
]
},
{
"key": "radio2",
"type": "radios-inline",
"titleMap": [
{
"value": "Transistor",
"name": "Transistor <br> Not the tube kind."
},
{
"value": "Tube",
"name": "Tube <br> The tube kind."
}
]
},
{
"key": "radiobuttons",
"style": {
"selected": "btn-success",
"unselected": "btn-default"
},
"type": "radiobuttons",
"notitle": true
},
{
"type": "actions",
"items": [
{
"type": "submit",
"style": "btn-info",
"title": "Do It!"
},
{
"type": "button",
"style": "btn-danger",
"title": "Noooooooooooo",
"onClick": "sayNo()"
}
]
}
]`
Schema:
`{
"type": "object",
"required": [
"name",
"shoesizeLeft"
],
"properties": {
"name": {
"title": "Name",
"description": "Gimme yea name lad",
"type": "string",
"pattern": "^[^/]*$",
"minLength": 2
},
"invitation": {
"type": "string",
"format": "html",
"title": "Invitation Design",
"description": "Design the invitation in full technicolor HTML"
},
"favorite": {
"title": "Favorite",
"type": "string",
"enum": [
"undefined",
"null",
"NaN"
]
},
"shoesizeLeft": {
"title": "Shoe size (left)",
"default": 42,
"type": "number"
},
"shoesizeRight": {
"title": "Shoe size (right)",
"default": 42,
"type": "number"
},
"attributes": {
"type": "object",
"title": "Attributes",
"required": [
"eyecolor"
],
"properties": {
"eyecolor": {
"type": "string",
"format": "color",
"title": "Eye color",
"default": "pink"
},
"haircolor": {
"type": "string",
"title": "Hair color"
},
"shoulders": {
"type": "object",
"title": "Shoulders",
"properties": {
"left": {
"type": "string",
"title": "Left"
},
"right": {
"type": "string",
"title": "Right"
}
}
}
}
},
"things": {
"type": "array",
"title": "I like...",
"items": {
"type": "string",
"enum": [
"clowns",
"compiling",
"sleeping"
]
}
},
"dislike": {
"type": "array",
"title": "I dislike...",
"items": {
"type": "string",
"title": "I hate"
}
},
"soul": {
"title": "Terms Of Service",
"description": "I agree to sell my undying <a href='https://www.youtube.com/watch?v=dQw4w9WgXcQ'>soul</a>",
"type": "boolean",
"default": true
},
"soulserial": {
"title": "Soul Serial No",
"type": "string"
},
"date": {
"title": "Date of party",
"type": "string",
"format": "date"
},
"radio": {
"title": "Radio type",
"type": "string",
"enum": [
"Transistor",
"Tube"
]
},
"radio2": {
"title": "My Second Radio",
"type": "string",
"enum": [
"Transistor",
"Tube"
]
},
"radiobuttons": {
"type": "string",
"enum": [
"Select me!",
"No me!"
]
}
}
}`
From first glance, it seems to generate an ID on the first input field. So I presume it is related to the Key in the form and the title in the Schema.
ID fields are generated from the last segment of the key in old 0.x versions and a combined form name and object path in the next version code for 1.0.0 and beyond.
So from 1.0.0 onward you will have proper unique ids like:
formName--objectName-arrayName-4-property
While a class matching that will also be available along with a version without array positions: formName--objectName-arrayName-property
The combination of unique id and flexible classes should cater to any customisation needs.

Categories