From 1c3eab82aa7000d81397e7e73754541d12d6278f Mon Sep 17 00:00:00 2001 From: Reid Mello <30907815+rjmello@users.noreply.github.com> Date: Wed, 17 Aug 2022 23:53:41 -0400 Subject: [PATCH 1/3] Stop automatically populating File model name field with external source URLs --- src/cript/nodes/primary/file.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/cript/nodes/primary/file.py b/src/cript/nodes/primary/file.py index 27c1f66..f804587 100644 --- a/src/cript/nodes/primary/file.py +++ b/src/cript/nodes/primary/file.py @@ -1,7 +1,6 @@ import os from typing import Union from logging import getLogger -from urllib.parse import urlparse from beartype import beartype @@ -76,11 +75,8 @@ def source(self, value): self.name = os.path.basename(value) self.extension = os.path.splitext(value)[-1] - elif value.startswith(("http://", "https://")): - parsed_url = urlparse(value) - self.name = parsed_url.netloc + parsed_url.path - + pass else: raise FileNotFoundError( "The file could not be found on the local filesystem." From 4681d0e7885f25684523b35e3afba2630201fa72 Mon Sep 17 00:00:00 2001 From: Reid Mello <30907815+rjmello@users.noreply.github.com> Date: Thu, 18 Aug 2022 00:20:45 -0400 Subject: [PATCH 2/3] Support use of UI URLs for API.get method --- src/cript/api.py | 8 +++++++- src/cript/utils.py | 17 +++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/cript/api.py b/src/cript/api.py index 22a6b7c..970f2de 100644 --- a/src/cript/api.py +++ b/src/cript/api.py @@ -18,7 +18,12 @@ from cript.nodes.primary.user import User from cript.nodes.primary.file import File from cript.nodes.secondary.base_secondary import BaseSecondary -from cript.utils import get_api_url, convert_file_size, display_errors +from cript.utils import ( + get_api_url, + convert_to_api_url, + convert_file_size, + display_errors, +) from cript.exceptions import ( APIAuthError, APIRefreshError, @@ -615,6 +620,7 @@ def get( """ # Get node with a URL if isinstance(obj, str): + obj = convert_to_api_url(obj) if self.api_url not in obj: raise APIGetError("Please enter a valid node URL.") response = self.session.get(obj) diff --git a/src/cript/utils.py b/src/cript/utils.py index 08deb6f..a33459d 100644 --- a/src/cript/utils.py +++ b/src/cript/utils.py @@ -2,6 +2,7 @@ import hashlib import math import json +from urllib.parse import urlparse def get_api_url(host: str, tls: bool = True): @@ -21,6 +22,22 @@ def get_api_url(host: str, tls: bool = True): return f"{protocol}://{host}/api" +def convert_to_api_url(url: str): + """ + Convert a UI URL to an API URL. + e.g., https://criptapp.org/material/ --> https://criptapp.org/api/material/ + + :param url: The original UI URL that will be converted. + :return: The converted API URL. + :rtype: str + """ + parsed_url = urlparse(url) + scheme = parsed_url.scheme + netloc = parsed_url.netloc + path = parsed_url.path + return f"{scheme}://{netloc}/api{path}" + + def auto_assign_group(group, parent): """ Decide whether to inherit the group from a node's parent. From a62855beb1b6d358bcf5f608c1c69718c9f26f17 Mon Sep 17 00:00:00 2001 From: Reid Mello <30907815+rjmello@users.noreply.github.com> Date: Thu, 18 Aug 2022 00:21:22 -0400 Subject: [PATCH 3/3] Upgrade version: 0.4.1 --> 0.4.2 --- src/cript/VERSION.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cript/VERSION.txt b/src/cript/VERSION.txt index 44bb5d1..f7abe27 100644 --- a/src/cript/VERSION.txt +++ b/src/cript/VERSION.txt @@ -1 +1 @@ -0.4.1 \ No newline at end of file +0.4.2 \ No newline at end of file