Skip to content
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

【RFC】add metadata to FileBox #3

Closed
windmemory opened this issue Jul 29, 2018 · 8 comments
Closed

【RFC】add metadata to FileBox #3

windmemory opened this issue Jul 29, 2018 · 8 comments
Labels
enhancement New feature or request

Comments

@windmemory
Copy link
Contributor

Hi @zixia ,

I am working on sending voice message to other people in wechaty, and I realized that the voice length has to be passed when we send out voice message. And this information is pretty hard to be retrieved from the data, so I think it makes sense to add a metadata field in FileBox so for voice message that I received, I can persist the voice length in the metadata, then when use the FileBox voice file to send message, I can retrieve it from the FileBox object itself.

Currently I observed that there is a mimeType field in FileBox, and it is used only for url related FileBox object, I can possibly save the voice length inside that, or put it into the file name, but that is all work around, not elegant solutions. So I think the metadata field will be the final solution to my problem.

Please let me know your thought.

@huan
Copy link
Owner

huan commented Jul 29, 2018

It's a reasonable request, and it should be considering all the possible file box types.

I'll think about it and reply to you later. Before we have a metadata for FileBox, please keep using your workaround(which I feel it will work great).

@huan huan added the enhancement New feature or request label Jul 29, 2018
@huan
Copy link
Owner

huan commented Jul 30, 2018

Do you have any idea about how the new metadata() method should be designed, especially in your use case?

If you have any, a PR is welcome to demonstrate what you need, and we can go on discussing about it based on your PR.

@windmemory
Copy link
Contributor Author

Actually for my use case, I just need a key-value pair in side the metadata field. Like:

const f: FileBox = magicMethodGetMeOneFileBoxObject()
f.metadata.voiceLength = 9129392

So it could just be an Object for my use case. But you can make it more sophisticate to serve more file type.

huan added a commit that referenced this issue Jul 30, 2018
@huan
Copy link
Owner

huan commented Jul 30, 2018

You should get your metadata property with wechaty@0.19.117 (which will require the file-box@0.8.23)

huan added a commit to wechaty/wechaty that referenced this issue Jul 30, 2018
@windmemory
Copy link
Contributor Author

That was blazing fast for adding features :)

I had some additional thoughts about this feature, I came up with this idea when I was laying on bed last night, so sorry for late statement of this idea.

It would be better to have metadata that added by the original creator of the object, and can not be modified afterwards, so it would carry the most reliable information with it, since it was added by the owner of the object. For my case, I would like to add the voiceLength to the metadata and don't want people to modify that value, so I think this feature is valuable to me. And I can imagine other use cases that people who created the object want to keep some information with the object.

I think we can pass an Metadata object in the constructor, and the object passed in can not be modified, example code below:

const meta = { zelda: 'breath of the wind' }
const f = FileBox.fromBase64(data, meta)

// When try to modify the data
f.metadata.zelda = 'game over'
// Expect an error thrown out

Probably we can use deep-froze on the Metadata object or do a recursively Object.freeze() on the Metadata.

What do you think about this?

@huan
Copy link
Owner

huan commented Jul 31, 2018

It's fast because this feature makes sense for the use cases.

I feel it's enough to use just Object.freeze() instead of doing a recursively because it will be too expensive.

Should be ready for use with the code from the latest master branch. (v0.8.24 or above)

@huan
Copy link
Owner

huan commented Jul 31, 2018

Could you please help me to add a documentation entry in README for the new metadata usage?

@windmemory
Copy link
Contributor Author

PRed: #4

Please revise the PR if you see anything improper, I am closing this issue since the feature is implemented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants