diff --git a/README.md b/README.md index 0b95179..0edccc2 100644 --- a/README.md +++ b/README.md @@ -9,12 +9,14 @@ Use "av-98.py --sync" to build a cache containing your bookmarks and all links i * FIXME1: doesn’t handle MIME other than text/gemini * FIXME2: consider root file is always index.gmi -* FIXME3: if a file exists in the cache where it should have been a folder, it fails (should instead remove the file) * FIXME4: certificates error are not handled in --synconly * FIXME5: offline web browser use os.system because it’s the only one that understands the ">> file.txt" -* FIXME6: sync-only always tries to download "uncachable" content (such as XML, forms, gopher…) This is somewhat related to FIXME1. +* FIXME6: sync-only always tries to download "uncachable" content (such as XML, forms, gopher…) This is somewhat related to FIXME1 and FIXME2. * TODO: number of cache updated in blackbox +* TODO: don’t add to tour when sync from tour/to_fetch +* TODO: don’t refresh is cache is young, even for bm +* TODO: https:// gemini:// should be understood without go This is a fork of the original [AV-98](https://tildegit.org/solderpunk/AV-98) by Solderpunk. diff --git a/av98.py b/av98.py index a319148..0b2aa66 100755 --- a/av98.py +++ b/av98.py @@ -158,13 +158,6 @@ class GeminiItem(): # of the file. if self.cache_path.endswith("/"): self.cache_path += "index.gmi" - elif not self.cache_path.endswith(".gmi"): - # That’s really a naughty hack - # but else, accessing gemini://mysite/~user while offline - # will truncate all relative links - # mysite/~user/page.gmi would become mysite/page.gmi - self.url += "/" - self.cache_path += "/index.gmi" def is_cache_valid(self): # TODO: Try to be smart about when to update a cache @@ -213,7 +206,8 @@ class GeminiItem(): Convert a relative URL to an absolute URL by using the URL of this GeminiItem as a base. """ - return urllib.parse.urljoin(self.url, relative_url) + abs_url = urllib.parse.urljoin(self.url, relative_url) + return abs_url def to_map_line(self, name=None): if name or self.name: @@ -419,10 +413,21 @@ you'll be able to transparently follow links to Gopherspace!""") print("original cache used ", gi.url) mime, body, tmpfile = self._get_cached(gi.url) elif self.offline_only: - #FIXME : how do we know MIME for cached content? - mime = "text/gemini" - if os.path.exists(gi.cache_path): - with open(gi.cache_path,'r') as file: + if os.path.isdir(gi.cache_path): + # if cache is a directory, then we redirect + # (similar to status 31 over the network) + new_url = gi.url + "/" + new_gi = GeminiItem(new_url,name=gi.name) + self._go_to_gi(new_gi) + return + else: + cached = gi.cache_path + if os.path.isfile(cached): + mime,encoding = mimetypes.guess_type(cached,strict=False) + #gmi Mimetype is not recognized yet + if not mime and cached.endswith('.gmi'): + mime = "text/gemini" + with open(cached,'r') as file: body = file.read() file.close() else: @@ -437,6 +442,7 @@ you'll be able to transparently follow links to Gopherspace!""") try: gi, mime, body, tmpfile = self._fetch_over_network(gi) ## We create the permanent cache for "text/gemini" + ## FIXME : try caching everything eles ? if mime == "text/gemini": cache_dir = os.path.dirname(gi.cache_path) os.makedirs(cache_dir,exist_ok=True)