Skip to content

Commit

Permalink
Merge pull request #21 from elblogbruno/fix-bugs-video-upload
Browse files Browse the repository at this point in the history
Fix bugs video upload
  • Loading branch information
elblogbruno authored May 31, 2021
2 parents 799c5a2 + 279fcf3 commit 2085601
Show file tree
Hide file tree
Showing 50 changed files with 817 additions and 4,442 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*.jks
key.properties
/Python-Server/output
/Python-Server/app/.idea
/Python-Server/.idea
/Python-Server/app/image_tagging/temp_image_folder
/Python-Server/app/__pycache__
/Python-Server/app/uploads
Expand Down
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [2.0.5]

### Added

- Now you can add Video files from web or phone!
- Started the base for adding a background worker that maintains the database, cleaning duplicated or blank content added. (Coming soon)
- Tags added from the AI tagging system have a number filter, so they are not all sent at the same time only the 10 first that are more used!

### Fixed
- More error handling and structure fix to make everything faster.
- Bug fix https://github.com/elblogbruno/NotionAI-MyMind/issues/20

## [2.0.4]

Expand Down Expand Up @@ -122,6 +133,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Fixed server issues adding callback capabilities. Before some websites images were not added due to timeouts.

[2.0.5]: https://github.com/elblogbruno/NotionAI-MyMind/releases/tag/2.0.5
[2.0.4]: https://github.com/elblogbruno/NotionAI-MyMind/releases/tag/2.0.4
[2.0.3]: https://github.com/elblogbruno/NotionAI-MyMind/releases/tag/2.0.3
[2.0.2]: https://github.com/elblogbruno/NotionAI-MyMind/releases/tag/2.0.2
Expand Down
74 changes: 51 additions & 23 deletions Chrome and Firefox Extension/js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var menuConfig = null;
if (usePromise){
menuConfig = [
{
title: `${browser.i18n.getMessage("add_text")}: %s`,
title: `${browser.i18n.getMessage("add_text")} %s`,
id: "naimm-add",
contexts: [ "selection", "image", "video", "audio" ]
},
Expand All @@ -28,7 +28,7 @@ if (usePromise){
}else{
menuConfig = [
{
title: `${chrome.i18n.getMessage("add_text")}: %s`,
title: `${chrome.i18n.getMessage("add_text")} %s`,
id: "naimm-add",
contexts: [ "selection", "image", "video", "audio" ]
},
Expand Down Expand Up @@ -135,27 +135,47 @@ async function GetMindStructure(sendResponse = null) {

async function AddUrlToMind(tab) {
let struct = await getFromStorage("mind_structure");
var url = tab.url;
var tab_url = tab.url;
var title = tab.title;
//const urlParams = `add_url_to_mind?url=${url}&title=${title}&collection_index=${collection_index}`;

createCollectionHandler(
() =>
showCollectionPopup(String(struct) , (result) => ApiRequest(`add_url_to_mind?url=${url}&title=${title}&collection_index=${result}`))
showCollectionPopup(String(struct) , (result) => UrlRequest(title,tab_url,result))
);
}

async function UrlRequest(title,tab_url,collection_index){
var url = new URL("http://foo.bar/add_url_to_mind");

url.searchParams.append('collection_index', collection_index);
url.searchParams.append('url', tab_url);
url.searchParams.append('title', title);

ApiRequest(url);
}

//Adds text to mind
async function AddTextToMind(info,tab) {
var text = info.selectionText;
var url = tab.url;
//urlParams = `add_text_to_mind?url=${url}&collection_index=${collection_index}&text=${text}`;

var tab_url = tab.url;

let struct = await getFromStorage("mind_structure");
createCollectionHandler(
() =>
showCollectionPopup(String(struct) , (result) => ApiRequest(`add_text_to_mind?url=${url}&collection_index=${result}&text=${text}`))
showCollectionPopup(String(struct) , (result) => TextRequest(text,tab_url,result))
);
}

async function TextRequest(text,tab_url,collection_index){
var url = new URL("http://foo.bar/add_text_to_mind");

url.searchParams.append('collection_index', collection_index);
url.searchParams.append('url', tab_url);
url.searchParams.append('text', text);

ApiRequest(url);
}

async function ProcessSelection(info,tab) {
let struct = await getFromStorage("mind_structure");
createCollectionHandler(
Expand All @@ -165,35 +185,44 @@ async function ProcessSelection(info,tab) {
}

async function addSelectionToMind(info,collection_index){
var urlParams = "";

var url = info["linkUrl"];
switch (info["mediaType"]) {
case 'image':
var src = info["srcUrl"];
var image_src_url = info["pageUrl"];
urlParams = `add_image_to_mind?collection_index=${collection_index}&url=${url}&image_src=${src}&image_src_url=${image_src_url}`;
ApiRequest(urlParams);
var image_src = info["srcUrl"];
var page_url = info["pageUrl"];
var link_url = info["linkUrl"];
var url = new URL("http://foo.bar/add_image_to_mind");

url.searchParams.append('collection_index', collection_index);
url.searchParams.append('url', page_url);
url.searchParams.append('image_src', image_src);
url.searchParams.append('image_src_url', link_url);

ApiRequest(url);

break;
case 'video':
var src = info["srcUrl"];
var video_src_url = info["pageUrl"];
urlParams = `add_video_to_mind?collection_index=${collection_index}&url=${url}&video_src=${src}&video_src_url=${video_src_url}`;
ApiRequest(urlParams);
var page_url = info["pageUrl"];
var url = new URL("http://foo.bar/add_video_to_mind");

url.searchParams.append('collection_index', collection_index);
url.searchParams.append('url', page_url);
url.searchParams.append('video_src', src);

ApiRequest(url);

break;
case 'audio':
var src = info["srcUrl"];
var page_url = info["pageUrl"];
var url = new URL("http://foo.bar/add_audio_to_mind");

// If your expected result is "http://foo.bar/?x=1&y=2&x=42"
url.searchParams.append('collection_index', collection_index);
url.searchParams.append('url', page_url);
url.searchParams.append('audio_src', src);

ApiRequest(url);
// urlParams = `add_audio_to_mind?collection_index=${collection_index}&url=${page_url}&audio_src=${src}`;


break;
default:
break;
Expand Down Expand Up @@ -495,7 +524,6 @@ function createCollectionHandler(callback) {
}
//We have a callback here from when user chooses a collection index, so we call the function that makes a request to the api with the index.
function showCollectionPopup(structure,callback_from_caller) {
console.log(structure);
if (structure != null){
try {

Expand Down
2 changes: 1 addition & 1 deletion Chrome and Firefox Extension/manifest-firefox.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

"name": "Notion AI My Mind",
"description": "This extension allows to click to add any image or website to your MIND in notion, and forget about everything else.",
"version": "1.1.1",
"version": "1.1.2",

"browser_action": {
"default_icon": "icon/icon.png",
Expand Down
2 changes: 1 addition & 1 deletion Chrome and Firefox Extension/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

"name": "Notion AI My Mind",
"description": "This extension allows to click to add any image or website to your MIND in notion, and forget about everything else.",
"version": "1.1.1",
"version": "1.1.2",

"browser_action": {
"default_icon": "icon/icon.png",
Expand Down
7 changes: 7 additions & 0 deletions Extension - CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.1.2]

### Fixed

- Removed unused code.
- Fixed bugs.

## [1.1.1]

### Added
Expand Down
13 changes: 11 additions & 2 deletions Python-Server/.idea/Python-Server.iml

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

2 changes: 1 addition & 1 deletion Python-Server/.idea/misc.xml

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

2 changes: 1 addition & 1 deletion Python-Server/app/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ RUN apt-get update
RUN apt-get install git -y
RUN python -m pip install -r requirements.txt

WORKDIR /app
# WORKDIR /app
COPY . /app

CMD python server.py
71 changes: 71 additions & 0 deletions Python-Server/app/background_worker/background_worker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import schedule
import time
import threading


## coming soon
class Worker:
def __init__(self, client, notion_ai):
self.client = client
self.notion_ai = notion_ai
# self.background_job()
# schedule.every().minute.do(self.background_job)

# Start the background thread
# stop_run_continuously = self.run_continuously()

# Do some other things...
# time.sleep(10)

# Stop the background thread
# stop_run_continuously.set()

def run_continuously(self, interval=1):
"""Continuously run, while executing pending jobs at each
elapsed time interval.
@return cease_continuous_run: threading. Event which can
be set to cease continuous run. Please note that it is
*intended behavior that run_continuously() does not run
missed jobs*. For example, if you've registered a job that
should run every minute and you set a continuous run
interval of one hour then your job won't be run 60 times
at each interval but only once.
"""
cease_continuous_run = threading.Event()

class ScheduleThread(threading.Thread):
@classmethod
def run(cls):
while not cease_continuous_run.is_set():
schedule.run_pending()
time.sleep(interval)

continuous_thread = ScheduleThread()
continuous_thread.start()
return cease_continuous_run

def myFunc(self, e):
return e.title == ""

def background_job(self):
print('Hello from the background thread')
number_of_collections = self.notion_ai.mind_structure.get_number_of_collections()
for i in range(0, number_of_collections):
collection_id, id = self.notion_ai.mind_structure.get_collection_by_index(
i) # collection is our database or "mind" in notion, as be have multiple, if not suplied, it will get the first one as the priority one.
collection = self.client.get_collection(collection_id=collection_id)

cv = collection.parent.views[0]
print(cv)
# Run a "filtered" query (inspect network tab in browser for examples, on queryCollection calls)
filter_params = {
"filters": [{
"filter": {
"operator": "is_empty"
},
"property": "title"
}],
"operator": "and"
}
result = cv.build_query(filter=filter_params).execute()
print("Things assigned to me:", result)
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,21 @@
from clarifai_grpc.grpc.api.status import status_code_pb2
from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel


class ClarifaiAI:

def __init__(self,key):
def __init__(self, key):
# Construct one of the channels you want to use
self.channel = ClarifaiChannel.get_json_channel()
self.key = key

def get_tags(self,image_url, is_local_image, treshold):
def get_tags(self, image_url, is_local_image, treshold):
stub = service_pb2_grpc.V2Stub(self.channel)
file_bytes = {}
file = ""

if is_local_image:
file = "./uploads/"+image_url.split("/")[-1]
file = "./uploads/" + image_url.split("/")[-1]
with open(file, "rb") as f:
file_bytes = f.read()
else:
Expand Down Expand Up @@ -48,4 +49,4 @@ def get_tags(self,image_url, is_local_image, treshold):

print('Predicted:', tags)

return tags
return tags
Loading

0 comments on commit 2085601

Please sign in to comment.