Skip to content
This repository has been archived by the owner on Aug 22, 2023. It is now read-only.

Commit

Permalink
Merge pull request #16 from C-Accel-CRIPT/develop
Browse files Browse the repository at this point in the history
Merge develop into master
  • Loading branch information
rjmello authored Aug 18, 2022
2 parents 8b5f90f + a62855b commit 37c4d86
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/cript/VERSION.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.4.1
0.4.2
8 changes: 7 additions & 1 deletion src/cript/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 1 addition & 5 deletions src/cript/nodes/primary/file.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import os
from typing import Union
from logging import getLogger
from urllib.parse import urlparse

from beartype import beartype

Expand Down Expand Up @@ -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."
Expand Down
17 changes: 17 additions & 0 deletions src/cript/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import hashlib
import math
import json
from urllib.parse import urlparse


def get_api_url(host: str, tls: bool = True):
Expand All @@ -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.
Expand Down

0 comments on commit 37c4d86

Please sign in to comment.