Added "getMediaFilesNames" action (#247)
This commit is contained in:
parent
2081330c35
commit
929716c7b1
@ -93,6 +93,29 @@
|
||||
}
|
||||
```
|
||||
|
||||
* **getMediaFilesNames**
|
||||
|
||||
Gets the names of media files matched the pattern. Returning all names by default.
|
||||
|
||||
*Sample request*:
|
||||
```json
|
||||
{
|
||||
"action": "getMediaFilesNames",
|
||||
"version": 6,
|
||||
"params": {
|
||||
"pattern": "_hell*.txt"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
*Sample result*:
|
||||
```json
|
||||
{
|
||||
"result": ["_hello.txt"],
|
||||
"error": null
|
||||
}
|
||||
```
|
||||
|
||||
* **deleteMediaFile**
|
||||
|
||||
Deletes the specified file inside the media folder.
|
||||
|
@ -14,6 +14,7 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import base64
|
||||
import glob
|
||||
import hashlib
|
||||
import inspect
|
||||
import json
|
||||
@ -549,6 +550,12 @@ class AnkiConnect:
|
||||
return False
|
||||
|
||||
|
||||
@util.api()
|
||||
def getMediaFilesNames(self, pattern='*'):
|
||||
path = os.path.join(self.media().dir(), pattern)
|
||||
return [os.path.basename(p) for p in glob.glob(path)]
|
||||
|
||||
|
||||
@util.api()
|
||||
def deleteMediaFile(self, filename):
|
||||
try:
|
||||
|
@ -16,6 +16,9 @@ class TestMedia(unittest.TestCase):
|
||||
media = util.invoke('retrieveMediaFile', filename=filename)
|
||||
self.assertEqual(media, data)
|
||||
|
||||
names = util.invoke('getMediaFilesNames', pattern='_tes*.txt')
|
||||
self.assertEqual(names, [filename])
|
||||
|
||||
# deleteMediaFile
|
||||
util.invoke('deleteMediaFile', filename=filename)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user