rejetto/hfs

Enable mixed-content requests

Closed this issue · 7 comments

First of all, i would like to explain what i want to achieve.

I store movies and series on my hfs server. I wanted to create a user specific bookmark (is_watched) server.
By this i mean to save the movie ids or urls that i have already watched. The idea was to further expand the Mark-news plugin with my custom logic.
If isNew -> Show the new txt, else if i have already watched it then show an eye emoji or something.
I would use min-media-player v1.16 by SanokKule plugin to save the progress. (Example: Add video progress listener -> Save watched flag if progress > 50)

Where should i store the data?
I made a simple http web server in python that accesses a .db file and accepts only 2 types of request.
Request example: GET -> /hasBookmark?{userId}&{contentId} POST -> /saveBookmark -- Payload(userId, contentId)
The problem is that the hfs server that uses https refuses to communicate with the bookmark server that uses http.
So my question is, is it possible to make hfs communicate with the python server? Preferably within localhost on my server pc.
The original idea was to not expose this server to the internet so I wouldn't have to deal with security issues.

Error_1

Error_2

Thank you!

Yes. I tried to access my python server from the custom plugin.

image

I will check it soon and write what i found.

by the way, the error you got has nothing to do with HFS, it's a limit of the browser. I'm not aware of any way to avoid that.
Anyway, it's 100x better to no use a python server just to store some data.
Now I'm home, and i'm realizing that your code is frontend (browser), so you cannot use DIRECTLY the openDb, because that's available backend-side (in file plugin.js).
What you need to do is to call HFS instead of your server, so you won't be blocked by the browser.

With HFS 0.54 (still in alpha) it's much easier, as you have "customRest" to define your server-side and "HFS.customRestCall" to call it from the browser.
So, if you want try with 0.54, you'll find documentation at https://github.com/rejetto/hfs/blob/54/dev-plugins.md
and an example at https://github.com/rejetto/copy-files/blob/api09.1/dist/plugin.js

But this is just a simplification/standardization, and you can reach your goal also with 0.53. With this version you can use HFS.call('killer/hasBookmark', { id, user }) in the browser, but you'll have to use "middleware" to intercept the hasBookmark request in plugin.js, something like this (but i didn't test it, it should be reviewed)

exports init = api => {
  const db = await api.openDb('bookmarks')
  return {
     middleware(ctx) {
        if (ctx.path === api.Const.API_URI + 'killer/hasBookmark') {
           const {params} = ctx.state
           db.put(params.id, params.user)  
        }
    }
}

Sorry for the mixed content question, my chatgpt "friend" said that it could be a limitation on the server side.
Thanks for the help, i managed to write a plugin and after a few modifications i was able to achieve what i wanted.

New movies with new badge
all_new

A new movie with new badge and a watched movie with eye badge.
one_new_one_watched

And sorry for the stupid questions, i develop android apps and web development is a bit alien technology for me. 😄

cool!
closing this issue then.
consider publishing your plugin when you feel confortable with it.