From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id WDR/OqeJQWO3ZgEAbAwnHQ (envelope-from ) for ; Sat, 08 Oct 2022 16:31:04 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id mKWhOaeJQWO6WwAAG6o9tA (envelope-from ) for ; Sat, 08 Oct 2022 16:31:03 +0200 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 733132D672 for ; Sat, 8 Oct 2022 16:31:03 +0200 (CEST) Received: from localhost ([::1]:33334 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ohAr0-0006Av-9B for larch@yhetil.org; Sat, 08 Oct 2022 10:31:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37944) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ohApp-00069J-9M for emacs-orgmode@gnu.org; Sat, 08 Oct 2022 10:29:49 -0400 Received: from mout01.posteo.de ([185.67.36.65]:60683) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ohApl-0003xe-RP for emacs-orgmode@gnu.org; Sat, 08 Oct 2022 10:29:48 -0400 Received: from submission (posteo.de [185.67.36.169]) by mout01.posteo.de (Postfix) with ESMTPS id CD836240029 for ; Sat, 8 Oct 2022 16:29:38 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1665239380; bh=Fvm8WQt0tnJCUXwxf3OmwSXdZqPmtfMq2j1ujdQOqDg=; h=From:To:Subject:Date:From; b=n5/m3lERbRlXb+KFaa/WYeWVweaGckNShZRSxBtJKPupaZimp1wWH2/3Ri7w0kVVI L9NGgbpyXl/UIJ/W7y3WWpdEEBqpVf9Cl8f3yJX/i76cdMpFCPA9Er/4SbG/AJ7wQE EsmM1k3C+WhYQchKfJJGKYD0q+isPDY636sofvqMYQlEGRglNpCHPgumcd2iCO7+UE Ep/ZZvsd/DbCVrNYD6Yy4d0377GO9YBbcNFr8cJIoHsBwOX9H23zgeiwRtzlRjqGNT BXtx/G0mbPMonKI+3rQ8KoBN5jUCdp40sKrkwTVvDgNY3cTbchP3T/XpHrtcWQlRAo jOgBF48zYzVOw== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4Ml6y96D8cz9rxM for ; Sat, 8 Oct 2022 16:29:37 +0200 (CEST) From: =?utf-8?Q?Juan_Manuel_Mac=C3=ADas?= To: orgmode Subject: [tip] Create and Insert a public Nextcloud/Owncloud link Date: Sat, 08 Oct 2022 14:29:35 +0000 Message-ID: <87bkqme6cw.fsf@posteo.net> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Received-SPF: pass client-ip=185.67.36.65; envelope-from=maciaschain@posteo.net; helo=mout01.posteo.de X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Migadu-Flow: FLOW_IN X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1665239463; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:list-id:list-help: list-unsubscribe:list-subscribe:list-post:dkim-signature; bh=xeTYK9GptiZVYepESHnbhgMQRihOSuRl6+BII0WiOjo=; b=B1v4EKirLuYcU6gla5loT9JlkfRGUvmt1/YPUe2qACVa8NITPrDHBLPeZqctczsQ5kUmBQ satwTO2OHWdL/7o0q0MKBxjPBxf1NdjYUGxSkKpjw2rCtiVfGSmA+Tu1UlHBYYLh2Ytw52 9sGBGF13RlUDHftBoEcgNHueLYjTJpADYzMGBnJcmvznZSvaI9NGpYM0GwSM7KXdlg63WM sdHEIGg17uAtcnGbcMLCdUgj6exTYrdDuofk4LZNT71iSc8tCeLC5POOQz0WIZj2bm7mYE wRZsRULezIqVTlZ4Blaxu9Htn1GIy3AfuEPJGfnRuK8vPJlR6Gfswtq7WuZCWw== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1665239463; a=rsa-sha256; cv=none; b=jMkdqIde2UphgqYv4QRd6HfQfku9JOZwNhOY0xN8pO6D+YAfDNqXtwL95hkDi1AS7wL1Y1 nqClHtVfLJHwr+BYrYg2ssz9GsqFtiC547cR8NM/mwqjZquHbDWEJoONY9uFbcLHQCuTLt nsTGcAJgwaPnV+I6ywKoTIKfoUrUs3H7gkxS9yeS0Q0UCXWTdhjUhnOlkVFjxV2oP1cb9u YGLpoF7h1UwFnNKkik385Bo1UkxcY4ps3sUQF/kl84/Obv5IOxx5AKDUa2YoXHxLvclNNU 2ILhtpSwailMrxw6jXfXC8+gIkUTTOC2Wolmk6Cixg4KFPPYkTzJV9FnbQdSOg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b="n5/m3lER"; dmarc=pass (policy=none) header.from=posteo.net; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: -8.78 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b="n5/m3lER"; dmarc=pass (policy=none) header.from=posteo.net; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: 733132D672 X-Spam-Score: -8.78 X-Migadu-Scanner: scn0.migadu.com X-TUID: pHRoMbxQfH/o Hi all, One of the few things that I miss from a desktop environment like Gnome Shell or KDE Plasma (currently I use EXWM), is the good integration these environments had with Nextcloud, as I am a heavy user of Nextcloud. Many times I need to create and share a public link to a file in my local folder. In the Nextcloud forum I learned how it can be done from the command line using curl, so starting from that, it wasn=E2=80=99t = very difficult to write this function in Elisp to insert a public link at point. It can be inserted in two ways: literally or as an Org bracket link, with description. For the function to work we must have: a) a folder within our local Nextcloud directory dedicated exclusively to public files; b) a line with our personal data in the ~/.authinfo file. Assuming, for example, that we use a third-party Nextcloud service like Disroot, the necessary line in authinfo would be: machine cloud.disroot.org login password And let=E2=80=99s go with the function. Before I have defined these three variables: =E2=94=8C=E2=94=80=E2=94=80=E2=94=80=E2=94=80 =E2=94=82 (defvar nextcloud-url "https://cloud.disroot.org") =E2=94=82 (defvar nextcloud-public-folder "~/disroot/Public/") =E2=94=82 (defvar nextcloud-public-folder-name "Public") =E2=94=94=E2=94=80=E2=94=80=E2=94=80=E2=94=80 And the function itself (caveat: the function is not asynchronous): =E2=94=8C=E2=94=80=E2=94=80=E2=94=80=E2=94=80 =E2=94=82 (defun insert-nextcloud-link () =E2=94=82 (interactive) =E2=94=82 (let* ((file-name (read-file-name "File: " =E2=94=82 nextcloud-public-folder)) =E2=94=82 (file (if (directory-name-p =E2=94=82 file-name) =E2=94=82 (replace-regexp-in-string =E2=94=82 (expand-file-name =E2=94=82 nextcloud-public-folder) =E2=94=82 "" =E2=94=82 file-name) =E2=94=82 (file-name-nondirectory file-name))) =E2=94=82 (desc =E2=94=82 (read-from-minibuffer =E2=94=82 "Link description (enter =3D no description): ")) =E2=94=82 (auth =E2=94=82 (nth 0 =E2=94=82 (auth-source-search =E2=94=82 :host "cloud.disroot.org" =E2=94=82 :requires '(user secret)))) =E2=94=82 (my-username (plist-get auth :user)) =E2=94=82 (my-passwd (funcall (plist-get auth :secret))) =E2=94=82 (result-raw (shell-command-to-string =E2=94=82 (concat "curl -u " =E2=94=82 "\"" =E2=94=82 my-username =E2=94=82 ":" =E2=94=82 my-passwd =E2=94=82 "\"" =E2=94=82 " -H \"OCS-APIRequest: true\" -X POST " =E2=94=82 nextcloud-url =E2=94=82 "/ocs/v1.php/apps/files_sharing/api/v1/shares -d path=3D" =E2=94=82 "\"" =E2=94=82 nextcloud-public-folder-name =E2=94=82 "/" =E2=94=82 file =E2=94=82 "\"" =E2=94=82 " -d shareType=3D3" =E2=94=82 " -d permissions=3D1"))) =E2=94=82 (result (with-temp-buffer =E2=94=82 (insert result-raw) =E2=94=82 (goto-char (point-min)) =E2=94=82 (re-search-forward "" nil t) =E2=94=82 (let ((desde (point))) =E2=94=82 (re-search-forward "<" nil t) =E2=94=82 (narrow-to-region desde (- (point) 1)) =E2=94=82 (buffer-string))))) =E2=94=82 (if (string=3D desc "") =E2=94=82 (insert result) =E2=94=82 (insert (format "[[%s][%s]]" result desc))))) =E2=94=94=E2=94=80=E2=94=80=E2=94=80=E2=94=80 Best regards, Juan Manuel=20